浏览代码

修改腾讯推送SDK兼容版本

Pq 1 年之前
父节点
当前提交
52d4b41b73

+ 3 - 1
TUIKit/TUIOfflinePush/tuiofflinepush/build.gradle

@@ -71,7 +71,9 @@ dependencies {
     // meizu
     compileOnly("com.tencent.timpush:meizu:7.7.5282")
     // OPPO
-    compileOnly ("com.tencent.timpush:oppo:7.7.5282")
+    //腾讯这边暂时不是最新的oppo,先引用极光的
+    compileOnly ("cn.jiguang.sdk.plugin:oppo:5.3.1")
+    compileOnly files('libs/com.heytap.msp_3.4.0.aar')
     compileOnly ('commons-codec:commons-codec:1.15')
     // vivo
 //    compileOnly ("com.tencent.timpush:vivo:7.7.5282")

二进制
TUIKit/TUIOfflinePush/tuiofflinepush/libs/com.heytap.msp_3.4.0.aar


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

@@ -7,7 +7,9 @@ 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;
@@ -43,7 +45,7 @@ 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();
                 }
@@ -97,46 +99,46 @@ 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)) {
+                    // 华为离线推送
+                    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);
                                 if (mPushCallback != null) {
-                                    mPushCallback.onTokenCallback(token);
+                                    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");
                                 }
                             }
-                        } 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();
                 }
@@ -146,24 +148,24 @@ public class OEMPushSetting implements PushSettingInterface {
 //                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);
+                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);
 
-                    // OPPO 手机默认关闭通知,需要申请
-                    HeytapPushManager.requestNotificationPermission();
+                        // OPPO 手机默认关闭通知,需要申请
+                        HeytapPushManager.requestNotificationPermission();
                     }
-                }catch (Exception e){
+                } catch (Exception e) {
                     e.printStackTrace();
                 }
                 break;
             case TUIOfflinePushConfig.BRAND_VIVO:
                 try {
-                // vivo离线推送
+                    // vivo离线推送
                     PushConfig config = new PushConfig.Builder()
                             .agreePrivacyStatement(true)
                             .build();
@@ -215,37 +217,37 @@ public class OEMPushSetting implements PushSettingInterface {
                 }
                 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());
+                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 (mPushCallback != null) {
-                                    TUIOfflinePushErrorBean errorBean = new TUIOfflinePushErrorBean();
-                                    errorBean.setErrorCode(TUIOfflinePushConfig.REGISTER_TOKEN_ERROR_CODE);
-                                    errorBean.setErrorDescription("fcm exception: " + task.getException());
-                                    mPushCallback.onTokenErrorCallBack(errorBean);
+                                    mPushCallback.onTokenCallback(token);
                                 } 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){
+                } catch (Exception e) {
                     e.printStackTrace();
                 }
                 break;
@@ -274,7 +276,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);

+ 4 - 4
TUIKit/TUIOfflinePush/tuiofflinepush/src/main/java/com/tencent/qcloud/tim/tuiofflinepush/oempush/OPPOPushImpl.java

@@ -12,8 +12,8 @@ public class OPPOPushImpl implements ICallBackResultService {
     private static final String TAG = OPPOPushImpl.class.getSimpleName();
 
     @Override
-    public void onRegister(int responseCode, String registerID) {
-        TUIOfflinePushLog.i(TAG, "onRegister responseCode: " + responseCode + " registerID: " + registerID);
+    public void onRegister(int responseCode, String registerID, String s1, String s2) {
+        TUIOfflinePushLog.i(TAG, "onRegister responseCode: " + responseCode + " registerID: " + registerID+"--s1:"+s1+"--s2:"+s2);
 
         if (OEMPushSetting.mPushCallback != null) {
             if (responseCode != 0) {
@@ -28,7 +28,7 @@ public class OPPOPushImpl implements ICallBackResultService {
     }
 
     @Override
-    public void onUnRegister(int responseCode) {
+    public void onUnRegister(int responseCode, String s, String s1) {
         TUIOfflinePushLog.i(TAG, "onUnRegister responseCode: " + responseCode);
     }
 
@@ -48,7 +48,7 @@ public class OPPOPushImpl implements ICallBackResultService {
     }
 
     @Override
-    public void onError(int i, String s) {
+    public void onError(int i, String s, String s1, String s2) {
         TUIOfflinePushLog.i(TAG, "onError code: " + i + " string: " + s);
     }