Переглянути джерело

修改兼容腾讯推送版本代码

Pq 1 рік тому
батько
коміт
a155d41228

+ 10 - 7
TUIKit/TUIOfflinePush/tuiofflinepush/build.gradle

@@ -67,19 +67,22 @@ dependencies {
     // for Google Analytics. This is recommended, but not required.
     //implementation 'com.google.firebase:firebase-analytics'
     // xiaomi
-    compileOnly ("com.tencent.tpns:xiaomi:1.3.7.2-release")
+    compileOnly ("com.tencent.timpush:xiaomi:7.7.5282")
     // meizu
-    compileOnly("com.tencent.tpns:meizu:1.3.3.3-release")
+    compileOnly("com.tencent.timpush:meizu:7.7.5282")
     // OPPO
-    compileOnly ("com.tencent.tpns:oppo:1.3.3.3-release")
+    compileOnly ("com.tencent.timpush:oppo:7.7.5282")
     compileOnly ('commons-codec:commons-codec:1.15')
     // vivo
-    compileOnly ("com.tencent.tpns:vivo:1.3.3.3-release")
+//    compileOnly ("com.tencent.timpush:vivo:7.7.5282")
+    //腾讯这边暂时不是最新的vivo,先引用极光的
+    compileOnly ("cn.jiguang.sdk.plugin:vivo:5.3.1")
+    // 接入 VIVO 厂商
     // huawei
-    compileOnly ('com.tencent.tpns:huawei:1.3.7.2-release')
-    compileOnly ('com.huawei.hms:push:6.10.0.300')
+    compileOnly ('com.tencent.timpush:huawei:7.7.5282')
+    compileOnly ('com.huawei.hms:push:6.12.0.300')
     // honor
-    compileOnly ('com.tencent.tpns:honor:1.3.3.3-release')
+    compileOnly ('com.tencent.timpush:honor:7.7.5282')
 
     if (!UNIAPP_MODEL) {
         def projects = this.rootProject.getAllprojects().stream().map { project -> project.name }.collect()

+ 1 - 1
TUIKit/TUIOfflinePush/tuiofflinepush/src/main/java/com/tencent/qcloud/tim/tuiofflinepush/oempush/HUAWEIHmsMessageService.java

@@ -28,7 +28,7 @@ public class HUAWEIHmsMessageService extends HmsMessageService {
     public void onNewToken(String token) {
         TUIOfflinePushLog.i(TAG, "onNewToken token=" + token);
 
-        if (com.tencent.qcloud.tim.tuiofflinepush.oempush.OEMPushSetting.mPushCallback != null) {
+        if (OEMPushSetting.mPushCallback != null) {
             OEMPushSetting.mPushCallback.onTokenCallback(token);
         }
     }

+ 136 - 118
TUIKit/TUIOfflinePush/tuiofflinepush/src/main/java/com/tencent/qcloud/tim/tuiofflinepush/oempush/OEMPushSetting.java

@@ -7,15 +7,19 @@ import android.content.Context;
 import android.net.Uri;
 import android.os.Build;
 import android.text.TextUtils;
-
+import androidx.annotation.NonNull;
 import com.google.android.gms.common.ConnectionResult;
 import com.google.android.gms.common.GoogleApiAvailability;
 import com.google.firebase.messaging.FirebaseMessaging;
 import com.heytap.msp.push.HeytapPushManager;
+import com.hihonor.push.sdk.HonorInstanceId;
+import com.hihonor.push.sdk.HonorMessaging;
+import com.hihonor.push.sdk.tasks.OnCompleteListener;
 import com.huawei.agconnect.config.AGConnectServicesConfig;
 import com.huawei.hms.aaid.HmsInstanceId;
 import com.huawei.hms.common.ApiException;
 import com.huawei.hms.push.HmsMessaging;
+import com.meizu.cloud.pushsdk.PushManager;
 import com.tencent.qcloud.tim.tuiofflinepush.PrivateConstants;
 import com.tencent.qcloud.tim.tuiofflinepush.TUIOfflinePushConfig;
 import com.tencent.qcloud.tim.tuiofflinepush.interfaces.PushCallback;
@@ -25,10 +29,10 @@ import com.tencent.qcloud.tim.tuiofflinepush.utils.TUIOfflinePushErrorBean;
 import com.tencent.qcloud.tim.tuiofflinepush.utils.TUIOfflinePushLog;
 import com.vivo.push.IPushActionListener;
 import com.vivo.push.PushClient;
+import com.vivo.push.PushConfig;
+import com.vivo.push.listener.IPushQueryActionListener;
 import com.xiaomi.mipush.sdk.MiPushClient;
 
-import androidx.annotation.NonNull;
-
 public class OEMPushSetting implements PushSettingInterface {
     private static final String TAG = OEMPushSetting.class.getSimpleName();
     protected static PushCallback mPushCallback = null;
@@ -39,53 +43,53 @@ public class OEMPushSetting implements PushSettingInterface {
             case TUIOfflinePushConfig.BRAND_XIAOMI:
                 // 小米离线推送
                 try {
-                    MiPushClient.registerPush(context, PrivateConstants.xiaomiPushAppId, PrivateConstants.xiaomiPushAppKey);
+                MiPushClient.registerPush(context, PrivateConstants.xiaomiPushAppId, PrivateConstants.xiaomiPushAppKey);
                 } catch (Exception e) {
                     e.printStackTrace();
                 }
                 break;
             case TUIOfflinePushConfig.BRAND_HONOR:
                 try {
-//                    HonorMessaging.getInstance(context).turnOnPush().addOnCompleteListener(new OnCompleteListener<Void>() {
-//                        @Override
-//                        public void onComplete(com.hihonor.push.sdk.tasks.Task<Void> task) {
-//                            if (task.isSuccessful()) {
-//                                TUIOfflinePushLog.i(TAG, "Honor turnOn push successfully.");
-//                            } else {
-//                                TUIOfflinePushLog.i(TAG, "Honor turnOn push failed." + task.getException());
-//                            }
+//                HonorMessaging.getInstance(context).turnOnPush().addOnCompleteListener(new OnCompleteListener<Void>() {
+//                    @Override
+//                    public void onComplete(com.hihonor.push.sdk.tasks.Task<Void> task) {
+//                        if (task.isSuccessful()) {
+//                            TUIOfflinePushLog.i(TAG, "Honor turnOn push successfully.");
+//                        } else {
+//                            TUIOfflinePushLog.i(TAG, "Honor turnOn push failed." + task.getException());
 //                        }
-//                    });
+//                    }
+//                });
 //
-//                    new Thread(new Runnable() {
-//                        @Override
-//                        public void run() {
-//                            try {
-//                                String pushToken = HonorInstanceId.getInstance(context).getPushToken();
-//                                TUIOfflinePushLog.i(TAG, "Honor get pushToken " + pushToken);
+//                new Thread(new Runnable() {
+//                    @Override
+//                    public void run() {
+//                        try {
+//                            String pushToken = HonorInstanceId.getInstance(context).getPushToken();
+//                            TUIOfflinePushLog.i(TAG, "Honor get pushToken " + pushToken);
 //
-//                                // 判断pushToken是否为空
-//                                if (!TextUtils.isEmpty(pushToken)) {
-//                                    // PushToken保存到您的服务器上
-//                                    if (mPushCallback != null) {
-//                                        mPushCallback.onTokenCallback(pushToken);
-//                                    } else {
-//                                        TUIOfflinePushLog.e(TAG, "mPushCallback is null");
-//                                    }
-//                                }
-//                            } catch (com.hihonor.push.sdk.common.data.ApiException e) {
-//                                TUIOfflinePushLog.e(TAG, "Honor get pushToken failed, " + e);
+//                            // 判断pushToken是否为空
+//                            if (!TextUtils.isEmpty(pushToken)) {
+//                                // PushToken保存到您的服务器上
 //                                if (mPushCallback != null) {
-//                                    TUIOfflinePushErrorBean errorBean = new TUIOfflinePushErrorBean();
-//                                    errorBean.setErrorCode(TUIOfflinePushConfig.REGISTER_TOKEN_ERROR_CODE);
-//                                    errorBean.setErrorDescription("honor ApiException: " + e);
-//                                    mPushCallback.onTokenErrorCallBack(errorBean);
+//                                    mPushCallback.onTokenCallback(pushToken);
 //                                } else {
 //                                    TUIOfflinePushLog.e(TAG, "mPushCallback is null");
 //                                }
 //                            }
+//                        } catch (com.hihonor.push.sdk.common.data.ApiException e) {
+//                            TUIOfflinePushLog.e(TAG, "Honor get pushToken failed, " + e);
+//                            if (mPushCallback != null) {
+//                                TUIOfflinePushErrorBean errorBean = new TUIOfflinePushErrorBean();
+//                                errorBean.setErrorCode(TUIOfflinePushConfig.REGISTER_TOKEN_ERROR_CODE);
+//                                errorBean.setErrorDescription("honor ApiException: " + e);
+//                                mPushCallback.onTokenErrorCallBack(errorBean);
+//                            } else {
+//                                TUIOfflinePushLog.e(TAG, "mPushCallback is null");
+//                            }
 //                        }
-//                    }).start();
+//                    }
+//                }).start();
                 } catch (Exception e) {
                     e.printStackTrace();
                 }
@@ -93,93 +97,107 @@ public class OEMPushSetting implements PushSettingInterface {
             case TUIOfflinePushConfig.BRAND_HUAWEI:
                 // 华为离线推送,设置是否接收Push通知栏消息调用示例
                 try {
-                    HmsMessaging.getInstance(context).turnOnPush().addOnCompleteListener(new com.huawei.hmf.tasks.OnCompleteListener<Void>() {
-                        @Override
-                        public void onComplete(com.huawei.hmf.tasks.Task<Void> task) {
-                            if (task.isSuccessful()) {
-                                TUIOfflinePushLog.i(TAG, "huawei turnOnPush Complete");
-                            } else {
-                                TUIOfflinePushLog.e(TAG, "huawei turnOnPush failed: ret=" + task.getException().getMessage());
-                            }
+                HmsMessaging.getInstance(context).turnOnPush().addOnCompleteListener(new com.huawei.hmf.tasks.OnCompleteListener<Void>() {
+                    @Override
+                    public void onComplete(com.huawei.hmf.tasks.Task<Void> task) {
+                        if (task.isSuccessful()) {
+                            TUIOfflinePushLog.i(TAG, "huawei turnOnPush Complete");
+                        } else {
+                            TUIOfflinePushLog.e(TAG, "huawei turnOnPush failed: ret=" + task.getException().getMessage());
                         }
-                    });
+                    }
+                });
 
-                    // 华为离线推送
-                    new Thread() {
-                        @Override
-                        public void run() {
-                            try {
-                                // read from agconnect-services.json
-                                String appId = AGConnectServicesConfig.fromContext(context).getString("client/app_id");
-                                String token = HmsInstanceId.getInstance(context).getToken(appId, "HCM");
-                                TUIOfflinePushLog.i(TAG, "huawei get token:" + token);
-                                if (!TextUtils.isEmpty(token)) {
-                                    if (mPushCallback != null) {
-                                        mPushCallback.onTokenCallback(token);
-                                    } else {
-                                        TUIOfflinePushLog.e(TAG, "mPushCallback is null");
-                                    }
-                                }
-                            } catch (ApiException e) {
-                                TUIOfflinePushLog.e(TAG, "huawei get token failed, " + e);
+                // 华为离线推送
+                new Thread() {
+                    @Override
+                    public void run() {
+                        try {
+                            // read from agconnect-services.json
+                            String appId = AGConnectServicesConfig.fromContext(context).getString("client/app_id");
+                            String token = HmsInstanceId.getInstance(context).getToken(appId, "HCM");
+                            TUIOfflinePushLog.i(TAG, "huawei get token:" + token);
+                            if (!TextUtils.isEmpty(token)) {
                                 if (mPushCallback != null) {
-                                    TUIOfflinePushErrorBean errorBean = new TUIOfflinePushErrorBean();
-                                    errorBean.setErrorCode(TUIOfflinePushConfig.REGISTER_TOKEN_ERROR_CODE);
-                                    errorBean.setErrorDescription("huawei ApiException: " + e);
-                                    mPushCallback.onTokenErrorCallBack(errorBean);
+                                    mPushCallback.onTokenCallback(token);
                                 } else {
                                     TUIOfflinePushLog.e(TAG, "mPushCallback is null");
                                 }
                             }
+                        } catch (ApiException e) {
+                            TUIOfflinePushLog.e(TAG, "huawei get token failed, " + e);
+                            if (mPushCallback != null) {
+                                TUIOfflinePushErrorBean errorBean = new TUIOfflinePushErrorBean();
+                                errorBean.setErrorCode(TUIOfflinePushConfig.REGISTER_TOKEN_ERROR_CODE);
+                                errorBean.setErrorDescription("huawei ApiException: " + e);
+                                mPushCallback.onTokenErrorCallBack(errorBean);
+                            } else {
+                                TUIOfflinePushLog.e(TAG, "mPushCallback is null");
+                            }
                         }
-                    }.start();
+                    }
+                }.start();
                 } catch (Exception e) {
                     e.printStackTrace();
                 }
                 break;
             case TUIOfflinePushConfig.BRAND_MEIZU:
-//                try {
-//                    // 魅族离线推送
-//                    PushManager.register(context, PrivateConstants.meizuPushAppId, PrivateConstants.meizuPushAppKey);
-//                } catch (Exception e) {
-//                    e.printStackTrace();
-//                }
+                // 魅族离线推送
+//                PushManager.register(context, PrivateConstants.meizuPushAppId, PrivateConstants.meizuPushAppKey);
                 break;
             case TUIOfflinePushConfig.BRAND_OPPO:
                 try{
-                    HeytapPushManager.init(context, false);
-                    if (HeytapPushManager.isSupportPush(context)) {
-                        // oppo离线推送
-                        OPPOPushImpl oppo = new OPPOPushImpl();
-                        oppo.createNotificationChannel(context);
-                        HeytapPushManager.register(context, PrivateConstants.oppoPushAppKey, PrivateConstants.oppoPushAppSecret, oppo);
+                HeytapPushManager.init(context, false);
+                if (HeytapPushManager.isSupportPush(context)) {
+                    // oppo离线推送
+                    OPPOPushImpl oppo = new OPPOPushImpl();
+                    oppo.createNotificationChannel(context);
+                    HeytapPushManager.register(context, PrivateConstants.oppoPushAppKey, PrivateConstants.oppoPushAppSecret, oppo);
 
-                        // OPPO 手机默认关闭通知,需要申请
-                        HeytapPushManager.requestNotificationPermission();
+                    // OPPO 手机默认关闭通知,需要申请
+                    HeytapPushManager.requestNotificationPermission();
                     }
                 }catch (Exception e){
                     e.printStackTrace();
                 }
                 break;
             case TUIOfflinePushConfig.BRAND_VIVO:
-                try{
-                    // vivo离线推送
-                    PushClient.getInstance(context).initialize();
+                try {
+                // vivo离线推送
+                    PushConfig config = new PushConfig.Builder()
+                            .agreePrivacyStatement(true)
+                            .build();
+                    PushClient.getInstance(context).initialize(config);
 
                     TUIOfflinePushLog.i(TAG, "vivo support push: " + PushClient.getInstance(context).isSupport());
                     PushClient.getInstance(context).turnOnPush(new IPushActionListener() {
                         @Override
                         public void onStateChanged(int state) {
                             if (state == 0) {
-                                String regId = PushClient.getInstance(context).getRegId();
-                                TUIOfflinePushLog.i(TAG, "vivopush open vivo push success regId = " + regId);
-                                if (mPushCallback != null) {
-                                    mPushCallback.onTokenCallback(regId);
-                                } else {
-                                    TUIOfflinePushLog.e(TAG, "mPushCallback is null");
-                                }
+                                PushClient.getInstance(context).getRegId(new IPushQueryActionListener() {
+                                    @Override
+                                    public void onSuccess(String s) {
+                                        TUIOfflinePushLog.i(TAG, "vivopush open vivo push success regId = " + s);
+                                        if (mPushCallback != null) {
+                                            mPushCallback.onTokenCallback(s);
+                                        } else {
+                                            TUIOfflinePushLog.e(TAG, "mPushCallback is null");
+                                        }
+                                    }
+
+                                    @Override
+                                    public void onFail(Integer integer) {
+                                        if (mPushCallback != null) {
+                                            TUIOfflinePushErrorBean errorBean = new TUIOfflinePushErrorBean();
+                                            errorBean.setErrorCode(integer);
+                                            errorBean.setErrorDescription("vivo error code: " + String.valueOf(integer));
+                                            mPushCallback.onTokenErrorCallBack(errorBean);
+                                        }
+                                    }
+                                });
                             } else {
-                                // 根据vivo推送文档说明,state = 101 表示该vivo机型或者版本不支持vivo推送,链接:https://dev.vivo.com.cn/documentCenter/doc/156
+                                // 根据vivo推送文档说明,state = 101
+                                // 表示该vivo机型或者版本不支持vivo推送,链接:https://dev.vivo.com.cn/documentCenter/doc/156
                                 TUIOfflinePushLog.e(TAG, "vivopush open vivo push fail state = " + state);
                                 if (mPushCallback != null) {
                                     TUIOfflinePushErrorBean errorBean = new TUIOfflinePushErrorBean();
@@ -192,40 +210,40 @@ public class OEMPushSetting implements PushSettingInterface {
                             }
                         }
                     });
-                }catch (Exception e){
-                    e.printStackTrace();
+                } catch (Exception e) {
+                    TUIOfflinePushLog.e(TAG, "register vivo e = " + e);
                 }
                 break;
             default:
                 try{
-                    if (isGoogleServiceSupport()) {
-                        FirebaseMessaging.getInstance().getToken().addOnCompleteListener(new com.google.android.gms.tasks.OnCompleteListener<String>() {
-                            @Override
-                            public void onComplete(@NonNull com.google.android.gms.tasks.Task<String> task) {
-                                if (!task.isSuccessful()) {
-                                    TUIOfflinePushLog.e(TAG, "getInstanceId failed exception = " + task.getException());
-                                    if (mPushCallback != null) {
-                                        TUIOfflinePushErrorBean errorBean = new TUIOfflinePushErrorBean();
-                                        errorBean.setErrorCode(TUIOfflinePushConfig.REGISTER_TOKEN_ERROR_CODE);
-                                        errorBean.setErrorDescription("fcm exception: " + task.getException());
-                                        mPushCallback.onTokenErrorCallBack(errorBean);
-                                    } else {
-                                        TUIOfflinePushLog.e(TAG, "mPushCallback is null");
-                                    }
-                                    return;
-                                }
-
-                                // Get new Instance ID token
-                                String token = task.getResult();
-                                TUIOfflinePushLog.i(TAG, "google fcm getToken = " + token);
-                                createPrivateNotification(context);
+                if (isGoogleServiceSupport()) {
+                    FirebaseMessaging.getInstance().getToken().addOnCompleteListener(new com.google.android.gms.tasks.OnCompleteListener<String>() {
+                        @Override
+                        public void onComplete(@NonNull com.google.android.gms.tasks.Task<String> task) {
+                            if (!task.isSuccessful()) {
+                                TUIOfflinePushLog.e(TAG, "getInstanceId failed exception = " + task.getException());
                                 if (mPushCallback != null) {
-                                    mPushCallback.onTokenCallback(token);
+                                    TUIOfflinePushErrorBean errorBean = new TUIOfflinePushErrorBean();
+                                    errorBean.setErrorCode(TUIOfflinePushConfig.REGISTER_TOKEN_ERROR_CODE);
+                                    errorBean.setErrorDescription("fcm exception: " + task.getException());
+                                    mPushCallback.onTokenErrorCallBack(errorBean);
                                 } else {
                                     TUIOfflinePushLog.e(TAG, "mPushCallback is null");
                                 }
+                                return;
+                            }
+
+                            // Get new Instance ID token
+                            String token = task.getResult();
+                            TUIOfflinePushLog.i(TAG, "google fcm getToken = " + token);
+                            createPrivateNotification(context);
+                            if (mPushCallback != null) {
+                                mPushCallback.onTokenCallback(token);
+                            } else {
+                                TUIOfflinePushLog.e(TAG, "mPushCallback is null");
                             }
-                        });
+                        }
+                    });
                     }
                 }catch (Exception e){
                     e.printStackTrace();
@@ -256,7 +274,7 @@ public class OEMPushSetting implements PushSettingInterface {
                 nm.createNotificationChannelGroup(notificationChannelGroup);
 
                 NotificationChannel notificationChannel =
-                        new NotificationChannel(PrivateConstants.fcmPushChannelId, "CustomGroup", NotificationManager.IMPORTANCE_HIGH);
+                    new NotificationChannel(PrivateConstants.fcmPushChannelId, "CustomGroup", NotificationManager.IMPORTANCE_HIGH);
                 notificationChannel.setGroup("MyGroupId");
                 notificationChannel.enableLights(true);
                 notificationChannel.enableVibration(true);