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;
29 import java.util.Objects;
36 public static final String
TAG =
"NIMClient";
70 final long startTime = System.currentTimeMillis();
71 if (LogDesensitizationConfigHelper.printToLogcat()) {
72 Log.i(TAG,
"NIMClient init");
74 SDKCache.config(context, info, options);
79 Handlers.sharedInstance().newMiscHandler().post(() -> {
80 ApiTraceEventManager.getInstance().recordPendingTrackEvent(startTime,
"NIMClient",
"init");
117 final long startTime = System.currentTimeMillis();
118 if (LogDesensitizationConfigHelper.printToLogcat()) {
119 Log.i(TAG,
"NIMClient config");
121 SDKCache.config(context, info, options);
125 SDKState.setProcessTag(2);
126 Handlers.sharedInstance().newMiscHandler().post(() -> {
127 ApiTraceEventManager.getInstance().recordPendingTrackEvent(startTime,
"NIMClient",
"config");
145 final long startTime = System.currentTimeMillis();
146 if (LogDesensitizationConfigHelper.printToLogcat()) {
147 Log.i(TAG,
"NIMClient initSDK");
151 Handlers.sharedInstance().newMiscHandler().post(() -> {
152 ApiTraceEventManager.getInstance().recordPendingTrackEvent(startTime,
"NIMClient",
"initSDK");
187 final long startTime = System.currentTimeMillis();
188 if (LogDesensitizationConfigHelper.printToLogcat()) {
189 Log.i(TAG,
"NIMClient initDelay");
194 SDKCache.config(context, info, options,
true,
true);
196 Handlers.sharedInstance().newMiscHandler().post(() -> {
197 ApiTraceEventManager.getInstance().recordPendingTrackEvent(startTime,
"NIMClient",
"initDelay");
203 final long startTime = System.currentTimeMillis();
204 Log.i(TAG,
"NIMClient initV2");
206 SDKCache.config(context, null, options,
false,
true,
true);
208 Handlers.sharedInstance().newMiscHandler().post(() -> {
209 ApiTraceEventManager.getInstance().recordPendingTrackEvent(startTime,
"NIMClient",
"initV2");
241 return SDKCacheUI.getService(clazz);
279 return APISyncHelper.syncRequest(future, time);
304 return APISyncHelper.syncRequest(future, 30 * 1000L);
313 String account = SDKCacheUI.getAccount();
327 String appKey = SDKCache.getAppKey();
333 }
catch (Exception e) {
344 return SDKStateUI.getStatus();
355 return SDKStateUI.getMode();
367 SDKCacheUI.toggleNotification(on);
380 SDKCacheUI.toggleRevokeMessageNotification(on);
392 SDKCacheUI.updateStatusBarNotificationConfig(config);
405 SDKCacheUI.updateStrings(strings);
416 return NimStorageUtil.getRootPath();
425 return BuildConfig.VERSION_NAME;
446 SDKCacheUI.updateTokenSceneConfig(config);
457 SDKCacheUI.updateCaptureDeviceInfoOption(captureDeviceInfoConfig);
467 if(!SDKCache.hasInited()){
468 NimLog.e(TAG,
"IM is not in init state");
471 if(TextUtils.isEmpty(appKey)){
472 NimLog.e(TAG,
"appKey is empty");
476 if(Objects.equals(appKey, SDKCache.getAppKey())){
477 NimLog.i(TAG,
"appKey is same as last time,no need to update");
481 if(SDKCacheUI.getAuthInfo() != null || SDKStateUI.getStatus() !=
StatusCode.
UNLOGIN){
482 NimLog.e(TAG,
"IM is not in logout state");
485 IChatRoomInteract interact = PluginInteractManager.getInstance().getInteract(IChatRoomInteract.class);
486 if (interact != null) {
487 boolean result = interact.isV2ChatroomAllDestroy();
489 NimLog.e(TAG,
"V2NIMChatroomClient is not all destroy");
494 SDKCache.setAppKey(appKey);
496 Handlers.sharedInstance().newHandler().post(() -> {
497 ABTestManager.getInstance().pullABTest(SDKCache.getContext(),
true);
498 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 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)
更新通知栏消息提醒配置,包括是否需要振动提醒、是否需要响铃提醒等。