|
@@ -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);
|