NIMSDK-AOS 10.4.0-beta
载入中...
搜索中...
未找到
NIMPushClient.java
浏览该文件的文档.
1package com.netease.nimlib.sdk.mixpush;
2
3
4import android.content.Context;
5import androidx.annotation.Nullable;
6import com.netease.nimlib.annotation.Keep;
7import com.netease.nimlib.log.NimLog;
8import com.netease.nimlib.mixpush.MixPushCache;
9import com.netease.nimlib.mixpush.TokenCallback;
10import com.netease.nimlib.mixpush.model.MixPushTokenImpl;
11import com.netease.nimlib.mixpush.platforms.MixPushPlatforms;
12import com.netease.nimlib.notifier.NotificationChannelCompat;
13import com.netease.nimlib.sdk.StatusBarNotificationConfig;
14
15/**
16 * 云信第三方推送接口
17 */
18@Keep
19@SuppressWarnings("java:S1144")
20public class NIMPushClient {
21
22 private static final String TAG = "NIMPushClient";
23
24 /**
25 *
26 * @param config
27 */
28 public static void initPush(MixPushConfig config) {
29 MixPushCache.init(config);
30 }
31 /**
32 * 注册第三方推送消息接收handler
33 * 在云信SDK初始化 NimClient.init 接口前调用
34 * @param handler 第三方推送消息接收handler, 可自定义通知栏点击行为
35 */
37 MixPushCache.setMixPushMessageHandler(handler);
38 }
39
40 /**
41 * 获取推送token,内部使用
42 * @param context
43 * @param notificationConfig 状态栏提醒的配置
44 * @param requestPushType 推送类型
45 * @param callback 回调
46 */
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}
Created by chenkang on 2017/11/20.
static void initPush(MixPushConfig config)
static void registerMixPushMessageHandler(MixPushMessageHandler handler)
注册第三方推送消息接收handler 在云信SDK初始化 NimClient.init 接口前调用
第三方推送消息回调接口,用户如果需要自行处理云信的第三方推送消息,则可实现该接口,并注册到NIMPushClient