NIMSDK-AOS  9.19.10
NIMPushClient.java
浏览该文件的文档.
1 package com.netease.nimlib.sdk.mixpush;
2 
3 
4 import android.content.Context;
5 import androidx.annotation.Nullable;
6 import com.netease.nimlib.annotation.Keep;
7 import com.netease.nimlib.log.NimLog;
8 import com.netease.nimlib.mixpush.MixPushCache;
9 import com.netease.nimlib.mixpush.MixPushCore;
10 import com.netease.nimlib.mixpush.TokenCallback;
11 import com.netease.nimlib.mixpush.model.MixPushTokenImpl;
12 import com.netease.nimlib.mixpush.platforms.MixPushPlatforms;
13 import com.netease.nimlib.notifier.NotificationChannelCompat;
15 
16 /**
17  * 云信第三方推送接口
18  */
19 @Keep
20 @SuppressWarnings("java:S1144")
21 public class NIMPushClient {
22 
23  private static final String TAG = "NIMPushClient";
24 
25  /**
26  *
27  * @param config
28  */
29  public static void initPush(MixPushConfig config) {
30  MixPushCache.init(config);
31  }
32  /**
33  * 注册第三方推送消息接收handler
34  * 在云信SDK初始化 NimClient.init 接口前调用
35  * @param handler 第三方推送消息接收handler, 可自定义通知栏点击行为
36  */
38  MixPushCache.setMixPushMessageHandler(handler);
39  }
40 
41  /**
42  * 获取推送token,内部使用
43  * @param context
44  * @param notificationConfig 状态栏提醒的配置
45  * @param requestPushType 推送类型
46  * @param callback 回调
47  */
48  private static void getPushToken(Context context, StatusBarNotificationConfig notificationConfig,int requestPushType,final IMixPushCallback<String> callback) {
49  if(callback == null){
50  return;
51  }
52  if(MixPushCache.getContext() == null){
53  MixPushCache.setContext(context);
54  }
55  if(MixPushCache.getNotificationConfig() == null){
56  MixPushCache.setNotificationConfig(notificationConfig);
57  }
58 
59  NotificationChannelCompat.createNIMMessageNotificationChannel(context,MixPushCache.getNotificationConfig());
60  TokenCallback tokenCallback = new TokenCallback(){
61  @Override
62  public void onToken(@Nullable MixPushTokenImpl pushToken) {
63  if (pushToken == null || pushToken.isNotValid()) {
64  // 获取token失败
65  NimLog.i(TAG,"getPushToken, reason: token null");
66  return;
67  }
68 
69  if (pushToken.getType() != requestPushType) {
70  // 获取token失败
71  NimLog.i(TAG,"getPushToken, reason: token type not match");
72  return;
73  }
74 
75  callback.onSuccess(pushToken.getToken());
76  }
77  };
78  MixPushConfig config = MixPushCache.getMixPushConfig();
79  if (config == null || !config.autoSelectPushType) {
80  MixPushPlatforms.registerPushSDK(context, requestPushType, tokenCallback);
81  } else {
82  MixPushPlatforms.registerAllPush(context, tokenCallback);
83  }
84  }
85 
86  /**
87  * 注册用户自主提供的推送token的回调,仅在 {@link MixPushConfig#manualProvidePushToken} 为true时有效
88  * @param callback 用户自主提供的推送token的回调
89  */
91  MixPushCore.setManuallyProvidePushTokenCallback(callback);
92  }
93 }
static void initPush(MixPushConfig config)
static void registerManuallyProvidePushTokenCallback(IManualProvidePushTokenCallback callback)
注册用户自主提供的推送token的回调,仅在 MixPushConfig#manualProvidePushToken 为true时有效 ...
第三方推送消息回调接口,用户如果需要自行处理云信的第三方推送消息,则可实现该接口,并注册到NIMPushClie...
static void registerMixPushMessageHandler(MixPushMessageHandler handler)
注册第三方推送消息接收handler 在云信SDK初始化 NimClient.init 接口前调用
Created by chenkang on 2017/11/20.
boolean autoSelectPushType
是否根据token自动选择推送类型