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);
81 Handlers.sharedInstance().newMiscHandler().post(() -> {
82 ApiTraceEventManager.getInstance().recordPendingTrackEvent(startTime,
"NIMClient",
"init");
119 final long startTime = System.currentTimeMillis();
120 if (LogDesensitizationConfigHelper.printToLogcat(options)) {
121 Log.i(TAG,
"NIMClient config");
123 SDKCache.config(context, info, options);
127 SDKState.setProcessTag(2);
128 Handlers.sharedInstance().newMiscHandler().post(() -> {
129 ApiTraceEventManager.getInstance().recordPendingTrackEvent(startTime,
"NIMClient",
"config");
147 final long startTime = System.currentTimeMillis();
148 if (LogDesensitizationConfigHelper.printToLogcat()) {
149 Log.i(TAG,
"NIMClient initSDK");
153 Handlers.sharedInstance().newMiscHandler().post(() -> {
154 ApiTraceEventManager.getInstance().recordPendingTrackEvent(startTime,
"NIMClient",
"initSDK");
189 final long startTime = System.currentTimeMillis();
190 if (LogDesensitizationConfigHelper.printToLogcat(options)) {
191 Log.i(TAG,
"NIMClient initDelay");
196 SDKCache.config(context, info, options,
true,
true);
198 Handlers.sharedInstance().newMiscHandler().post(() -> {
199 ApiTraceEventManager.getInstance().recordPendingTrackEvent(startTime,
"NIMClient",
"initDelay");
205 final long startTime = System.currentTimeMillis();
206 if (LogDesensitizationConfigHelper.printToLogcat(options)) {
207 Log.i(TAG,
"NIMClient initV2");
210 SDKCache.config(context, null, options,
false,
true,
true);
212 Handlers.sharedInstance().newMiscHandler().post(() -> {
213 ApiTraceEventManager.getInstance().recordPendingTrackEvent(startTime,
"NIMClient",
"initV2");
245 return SDKCacheUI.getService(clazz);
283 return APISyncHelper.syncRequest(future, time);
308 return APISyncHelper.syncRequest(future, 30 * 1000L);
317 String account = SDKCacheUI.getAccount();
331 String appKey = SDKCache.getAppKey();
337 }
catch (Exception e) {
348 return SDKStateUI.getStatus();
356 return SDKCache.safeGetOptions();
367 return SDKStateUI.getMode();
379 SDKCacheUI.toggleNotification(on);
392 SDKCacheUI.toggleRevokeMessageNotification(on);
404 SDKCacheUI.updateStatusBarNotificationConfig(config);
417 SDKCacheUI.updateStrings(strings);
428 return NimStorageUtil.getRootPath();
437 return BuildConfig.VERSION_NAME;
458 SDKCacheUI.updateTokenSceneConfig(config);
469 SDKCacheUI.updateCaptureDeviceInfoOption(captureDeviceInfoConfig);
479 if(!SDKCache.hasInited()){
480 NimLog.e(TAG,
"IM is not in init state");
483 if(TextUtils.isEmpty(appKey)){
484 NimLog.e(TAG,
"appKey is empty");
488 if(Objects.equals(appKey, SDKCache.getAppKey())){
489 NimLog.i(TAG,
"appKey is same as last time,no need to update");
493 if(SDKCacheUI.getAuthInfo() != null || SDKStateUI.getStatus() !=
StatusCode.
UNLOGIN){
494 NimLog.e(TAG,
"IM is not in logout state");
497 IChatRoomInteract interact = PluginInteractManager.getInstance().getInteract(IChatRoomInteract.class);
498 if (interact != null) {
499 boolean result = interact.isV2ChatroomAllDestroy();
501 NimLog.e(TAG,
"V2NIMChatroomClient is not all destroy");
506 SDKCache.setAppKey(appKey);
508 Handlers.sharedInstance().newHandler().post(() -> {
509 ABTestManager.getInstance().loadAndPullABTest(SDKCache.getContext(),
true);
510 NimEventStrategyManager.getInstance().reset();
SDK中用到的字符串定义。可用于开发者定制显示文案,以及实现SDK对多语言的支持。 目前仅新消息状态栏提醒...
static void toggleNotification(boolean on)
通知栏消息提醒开关。
static int isMainProcessPure(Context context)
判断当前进程是否是主进程(纯净版本),不会有隐私不合规风险,但是不保证100判断正确 ...
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)
更新通知栏消息提醒配置,包括是否需要振动提醒、是否需要响铃提醒等。