NIMSDK-AOS  10.5.0
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.TokenCallback;
10 import com.netease.nimlib.mixpush.model.MixPushTokenImpl;
11 import com.netease.nimlib.mixpush.platforms.MixPushPlatforms;
12 import com.netease.nimlib.notifier.NotificationChannelCompat;
14 
18 @Keep
19 @SuppressWarnings("java:S1144")
20 public class NIMPushClient {
21 
22  private static final String TAG = "NIMPushClient";
23 
28  public static void initPush(MixPushConfig config) {
29  MixPushCache.init(config);
30  }
37  MixPushCache.setMixPushMessageHandler(handler);
38  }
39 
47  private static void getPushToken(Context context, StatusBarNotificationConfig notificationConfig,int requestPushType,final IMixPushCallback<String> callback) {
48  if(callback == null){
49  return;
50  }
51  if(MixPushCache.getContext() == null){
52  MixPushCache.setContext(context);
53  }
54  if(MixPushCache.getNotificationConfig() == null){
55  MixPushCache.setNotificationConfig(notificationConfig);
56  }
57 
58  NotificationChannelCompat.createNIMMessageNotificationChannel(context,MixPushCache.getNotificationConfig());
59  TokenCallback tokenCallback = new TokenCallback(){
60  @Override
61  public void onToken(@Nullable MixPushTokenImpl pushToken) {
62  if (pushToken == null || pushToken.isNotValid()) {
63  // 获取token失败
64  NimLog.i(TAG,"getPushToken, reason: token null");
65  return;
66  }
67 
68  if (pushToken.getType() != requestPushType) {
69  // 获取token失败
70  NimLog.i(TAG,"getPushToken, reason: token type not match");
71  return;
72  }
73 
74  callback.onSuccess(pushToken.getToken());
75  }
76  };
77  MixPushConfig config = MixPushCache.getMixPushConfig();
78  if (config == null || !config.autoSelectPushType) {
79  MixPushPlatforms.registerPushSDK(context, requestPushType, tokenCallback);
80  } else {
81  MixPushPlatforms.registerAllPush(context, tokenCallback);
82  }
83  }
84 
85 }
static void initPush(MixPushConfig config)
第三方推送消息回调接口,用户如果需要自行处理云信的第三方推送消息,则可实现该接口,并注册到NIMPushClie...
static void registerMixPushMessageHandler(MixPushMessageHandler handler)
注册第三方推送消息接收handler 在云信SDK初始化 NimClient.init 接口前调用
Created by chenkang on 2017/11/20.
boolean autoSelectPushType
是否根据token自动选择推送类型