1 package com.netease.nimlib.sdk;
3 import android.app.Application;
4 import android.content.Context;
5 import android.text.TextUtils;
6 import android.util.Log;
31 import java.util.Objects;
38 public static final String
TAG =
"NIMClient";
72 final long startTime = System.currentTimeMillis();
73 if (LogDesensitizationConfigHelper.printToLogcat(options)) {
74 Log.i(TAG,
"NIMClient init");
76 SDKCache.config(context, info, options);
80 SDKState.setProcessTag(2);
81 SDKCacheUI.initServiceManager();
83 if (SDKCache.getOptions().asyncInitSDK) {
84 asyncInitUI(startTime,
"init",
"asyncInitSDK in init");
87 Handlers.sharedInstance().newMiscHandler().post(() -> {
88 ApiTraceEventManager.getInstance().recordPendingTrackEvent(startTime,
"NIMClient",
"init");
126 final long startTime = System.currentTimeMillis();
127 if (LogDesensitizationConfigHelper.printToLogcat(options)) {
128 Log.i(TAG,
"NIMClient config");
130 SDKCache.config(context, info, options);
135 SDKState.setProcessTag(2);
136 Handlers.sharedInstance().newMiscHandler().post(() -> {
137 ApiTraceEventManager.getInstance().recordPendingTrackEvent(startTime,
"NIMClient",
"config");
141 if (isMainProcess && SDKCache.isSingleProcessMode()
142 && ABTestConfigHelper.getUIConfigMode(context, options) == 1) {
143 NimLog.ui(
"pre-create UICore in config, uiConfigMode=1");
144 UICore.sharedInstance();
161 final long startTime = System.currentTimeMillis();
162 if (LogDesensitizationConfigHelper.printToLogcat()) {
163 Log.i(TAG,
"NIMClient initSDK");
165 SDKCacheUI.initServiceManager();
167 if (SDKCache.getOptions().asyncInitSDK) {
168 asyncInitUI(startTime,
"initSDK",
"asyncInitSDK in initSDK");
172 Handlers.sharedInstance().newMiscHandler().post(() -> {
173 ApiTraceEventManager.getInstance().recordPendingTrackEvent(startTime,
"NIMClient",
"initSDK");
209 final long startTime = System.currentTimeMillis();
210 if (LogDesensitizationConfigHelper.printToLogcat(options)) {
211 Log.i(TAG,
"NIMClient initDelay");
216 SDKState.setProcessTag(2);
217 SDKCache.config(context, info, options,
true,
true);
218 SDKCacheUI.initServiceManager();
220 if (SDKCache.getOptions().asyncInitSDK) {
221 asyncInitUI(startTime,
"initDelay",
"asyncInitSDK in initDelay");
224 Handlers.sharedInstance().newMiscHandler().post(() -> {
225 ApiTraceEventManager.getInstance().recordPendingTrackEvent(startTime,
"NIMClient",
"initDelay");
231 private static void asyncInitUI(
long startTime, String stage, String threadName) {
232 NimLog.ui(
"async initUI...");
233 SDKCacheUI.newCountDownLatch(1);
239 ApiTraceEventManager.getInstance().recordPendingTrackEvent(startTime,
"NIMClient", stage);
241 NimLog.ui(
"async initUI done!");
242 }
catch (Throwable throwable) {
243 NimLog.e(TAG,
"async initUI error", throwable);
244 SDKCacheUI.countDown();
246 }, threadName).start();
250 final long startTime = System.currentTimeMillis();
251 if (LogDesensitizationConfigHelper.printToLogcat(options)) {
252 Log.i(TAG,
"NIMClient initV2");
255 SDKState.setProcessTag(2);
256 SDKCache.config(context, null, options,
false,
true,
true);
258 Handlers.sharedInstance().newMiscHandler().post(() -> {
259 ApiTraceEventManager.getInstance().recordPendingTrackEvent(startTime,
"NIMClient",
"initV2");
291 return SDKCacheUI.getService(clazz);
329 return APISyncHelper.syncRequest(future, time);
354 return APISyncHelper.syncRequest(future, 30 * 1000L);
364 return ABTestManager.getInstance().getABTestHttpRawBody();
373 String account = SDKCacheUI.getAccount();
387 String appKey = SDKCache.getAppKey();
393 }
catch (Exception e) {
409 return SDKStateUI.getStatus();
417 return SDKCache.safeGetOptions();
428 return SDKStateUI.getMode();
440 SDKCacheUI.toggleNotification(on);
453 SDKCacheUI.toggleRevokeMessageNotification(on);
465 SDKCacheUI.updateStatusBarNotificationConfig(config);
478 SDKCacheUI.updateStrings(strings);
489 return NimStorageUtil.getRootPath();
498 return BuildConfig.VERSION_NAME;
519 SDKCacheUI.updateTokenSceneConfig(config);
530 SDKCacheUI.updateCaptureDeviceInfoOption(captureDeviceInfoConfig);
540 if(!SDKCache.hasInited()){
541 NimLog.e(TAG,
"IM is not in init state");
544 if(TextUtils.isEmpty(appKey)){
545 NimLog.e(TAG,
"appKey is empty");
549 if(Objects.equals(appKey, SDKCache.getAppKey())){
550 NimLog.i(TAG,
"appKey is same as last time,no need to update");
554 if(SDKCacheUI.getAuthInfo() != null || SDKStateUI.getStatus() !=
StatusCode.
UNLOGIN){
555 NimLog.e(TAG,
"IM is not in logout state");
558 IChatRoomInteract interact = PluginInteractManager.getInstance().getInteract(IChatRoomInteract.class);
559 if (interact != null) {
560 boolean result = interact.isV2ChatroomAllDestroy();
562 NimLog.e(TAG,
"V2NIMChatroomClient is not all destroy");
567 SDKCache.setAppKey(appKey);
569 Handlers.sharedInstance().newHandler().post(() -> {
570 ABTestManager.getInstance().loadAndPullABTest(SDKCache.getContext(),
true);
571 NimEventStrategyManager.getInstance().reset();
SDK中用到的字符串定义。可用于开发者定制显示文案,以及实现SDK对多语言的支持。 目前仅新消息状态栏提醒...
static void toggleNotification(boolean on)
通知栏消息提醒开关。
static int isMainProcessPure(Context context)
判断当前进程是否是主进程(纯净版本),不会有隐私不合规风险,但是不保证100判断正确 ...
static String getABTestHttpRawBody()
获取最近一次 ABTest HTTP 请求返回的原始 body。
static String getSDKVersion()
运行时获取当前 SDK 版本号。
static void updateStrings(NimStrings strings)
更新系统文案。
static void config(Context context, LoginInfo info, SDKOptions options)
[初始化 SDK 方式二] 在 Application#onCreate() 中配置 SDK(仅仅是配置,不影响性能),具体可配置的参数...
static boolean isMainProcess(Context context)
SDK 核心接口类,用于初始化 SDK,获取各个服务能力接口,获取当前状态等功能。
static String getSdkStorageDirPath()
获取 SDK 数据缓存目录路径。
static< T > RequestResult< T > syncRequest(InvocationFuture< T > future, long time)
在非 UI 线程中调用云信 SDK 异步 API,强制将异步调用转换为同步调用。
static< T > RequestResult< T > syncRequest(InvocationFuture< T > future)
在非 UI 线程调用云信 SDK 异步 API,强制将异步调用转换为同步调用。该接口已废弃,请使用 NIMClient#syncR...
static String getAppKey()
获取当前应用的 AppKey。
static void initSDK()
[初始化 SDK 方式二] 在 UI 进程主线程上按需初始化 SDK(不放在 Application#onCreate() 中初始化)。与 NI...
static StatusCode getStatus()
获取当前用户的状态。
static V2NIMError updateAppKey(String appKey)
更新 SDK 的 AppKey 当IM处于未登录状态,且所有聊天室实例全部销毁,且appkey不为null或空串时更新成功,否...
V2NIM_ERROR_CODE_INVALID_PARAMETER
参数错误
static SDKOptions getSDKOptions()
获取SDK初始化选项
static void toggleRevokeMessageNotification(boolean on)
撤回消息需要通知栏提醒的开关。
static void initDelay(Context context, LoginInfo info, SDKOptions options)
[初始化 SDK 方式三] 在 UI 进程主线程上按需初始化 SDK(不一定放在 Application#onCreate() 中初始化)。 ...
V2NIM_ERROR_CODE_SUCCESS
请求成功
static void updateCaptureDeviceInfoOption(CaptureDeviceInfoConfig captureDeviceInfoConfig)
更新获取设备信息的相关配置。包括配置是否获取产品型号、是否获取制造商信息、是否获取品牌信息,null 表示...
static void updateTokenSceneConfig(NosTokenSceneConfig config)
更新 SDK NOS Token 场景配置。对于 SDK NOS Token,云信 SDK 有默认值 ,若用户不单独配置,则直接采用默认...
static ModeCode getMode()
获取 SDK 当前的登录模式。
V2NIM_ERROR_CODE_ILLEGAL_STATE
非法状态
SDK nos token场景配置,不配置的话,走默认值,默认值只有以下3种场景:
static< T > T getService(Class< T > clazz)
获取云信各服务接口。
static void init(Context context, LoginInfo info, SDKOptions options)
[初始化 SDK 方式一] 在 Application#onCreate() 中调用该方法在应用启动时初始化 SDK。 ...
static String getCurrentAccount()
获取当前用户的 IM 账号(accid)。
static void initV2(Context context, SDKOptions options)
static void updateStatusBarNotificationConfig(StatusBarNotificationConfig config)
更新通知栏消息提醒配置,包括是否需要振动提醒、是否需要响铃提醒等。