| | |
| | | package com.hdl.photovoltaic; |
| | | |
| | | import android.app.Activity; |
| | | import android.app.ActivityManager; |
| | | import android.app.AlarmManager; |
| | | import android.app.Application; |
| | | import android.app.PendingIntent; |
| | | import android.app.NotificationChannel; |
| | | import android.app.NotificationManager; |
| | | import android.content.Context; |
| | | import android.content.Intent; |
| | | import android.content.res.Configuration; |
| | | import android.graphics.Color; |
| | | import android.os.Build; |
| | | import android.os.Handler; |
| | | import android.os.LocaleList; |
| | |
| | | |
| | | import androidx.multidex.MultiDex; |
| | | |
| | | import com.alibaba.sdk.android.push.CloudPushService; |
| | | import com.alibaba.sdk.android.push.CommonCallback; |
| | | import com.alibaba.sdk.android.push.noonesdk.PushInitConfig; |
| | | import com.alibaba.sdk.android.push.noonesdk.PushServiceFactory; |
| | | import com.alibaba.sdk.android.push.register.MiPushRegister; |
| | | import com.alibaba.sdk.android.push.register.OppoRegister; |
| | | import com.google.android.gms.common.ConnectionResult; |
| | | import com.google.android.gms.common.GoogleApiAvailability; |
| | | import com.google.firebase.messaging.FirebaseMessaging; |
| | |
| | | initAutoSize(); |
| | | // //初始化极光推送 |
| | | // initJPush(); |
| | | //谷歌原生fcm推送 |
| | | // 检查 Google Play Services 后再初始化 FCM |
| | | if (isGooglePlayServicesAvailable(this)) { |
| | | initFCM(); |
| | | } else { |
| | | HdlLogLogic.print("Google Play Services 不可用,无法使用 FCM", true); |
| | | // 可以在这里初始化备选推送方案(如阿里云自建通道) |
| | | } |
| | | // //谷歌原生fcm推送 |
| | | // // 检查 Google Play Services 后再初始化 FCM |
| | | // if (isGooglePlayServicesAvailable(this)) { |
| | | // initFCM(); |
| | | // } else { |
| | | // HdlLogLogic.print("Google Play Services 不可用,无法使用 FCM", true); |
| | | // // 可以在这里初始化备选推送方案(如阿里云自建通道) |
| | | // } |
| | | //阿里云推送 |
| | | initAliYunPush(); |
| | | initHDLLinkPMSdk(); |
| | | HDLLinkLocalSdk.getInstance().init(getInstance()); |
| | | initSocket(); |
| | |
| | | // //初始化友盟SDK,放在StartActivity里面初始化 |
| | | // initUMengSDK(); |
| | | |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 初始化阿里云推送 |
| | | */ |
| | | private void initAliYunPush() { |
| | | PushInitConfig pushInitConfig = new PushInitConfig.Builder() |
| | | .application(this) |
| | | .appKey("335628427") //请填写你自己的appKey,云端给的 |
| | | .appSecret("fd1dabe7ec494c878a5970d8646c83bc") //请填写你自己的appSecret,云端给的 |
| | | .build(); |
| | | PushServiceFactory.init(pushInitConfig); |
| | | CloudPushService pushService = PushServiceFactory.getCloudPushService(); |
| | | pushService.register(this, new CommonCallback() { |
| | | @Override |
| | | public void onSuccess(String success) { |
| | | String deviceId = pushService.getDeviceId(); |
| | | Log.d("com.aliyun.emas.pocdemo", "获取deviceId " + deviceId); |
| | | saveToken(deviceId); |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onFailed(String errorCode, String errorMessage) { |
| | | //错误码连接:https://help.aliyun.com/document_detail/434686.html?spm=a2c4g.11186623.0.0.62d3556dC2DqKJ#topic-1824037 |
| | | Log.d("com.aliyun.emas.pocdemo", "初始化失败,错误码: " + errorCode + "错误信息: " + errorMessage); |
| | | |
| | | } |
| | | }); |
| | | if (AppConfigManage.isDebug()) { |
| | | //仅适用于Debug包,正式包不需要此行 |
| | | pushService.setLogLevel(CloudPushService.LOG_DEBUG); |
| | | } |
| | | //小米 |
| | | //appKey/appSecret在小米开发者平台获取 |
| | | MiPushRegister.register(this, "2882303761520382032", "5612038223032"); |
| | | // OPPO通道注册 |
| | | //appKey/appSecret在OPPO开发者平台获取 |
| | | OppoRegister.register(this, "d80747c83e38442aaa2e5183c310bae0", "86afce21417b49a4984816024b15d4b9"); |
| | | |
| | | } |
| | | |
| | |
| | | Log.d("FCM", "FCM Token: " + token); |
| | | |
| | | // 保存 token |
| | | saveFCMToken(token); |
| | | saveToken(token); |
| | | }); |
| | | |
| | | // // 订阅主题(可选) |
| | |
| | | * |
| | | * @param token 令牌 |
| | | */ |
| | | public void saveFCMToken(String token) { |
| | | public void saveToken(String token) { |
| | | if (TextUtils.isEmpty(token.trim())) { |
| | | return; |
| | | } |
| | | UserConfigManage.getInstance().setPushToken(token); |
| | | UserConfigManage.getInstance().Save(); |
| | | |
| | | // // 发送到服务器 |
| | | // sendTokenToServer(token); |
| | | } |
| | | |
| | | |
| | |
| | | return this; |
| | | } |
| | | } |
| | | |
| | | // private void createNotificationChannel() { |
| | | // if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { |
| | | // NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); |
| | | // // 通知渠道的id。 |
| | | // String id = "ali_push_channel"; |
| | | // // 用户可以看到的通知渠道的名字。 |
| | | // CharSequence name = "notification channel"; |
| | | // // 用户可以看到的通知渠道的描述。 |
| | | // String description = "notification description"; |
| | | // int importance = NotificationManager.IMPORTANCE_HIGH; |
| | | // NotificationChannel mChannel = new NotificationChannel(id, name, importance); |
| | | // // 配置通知渠道的属性。 |
| | | // mChannel.setDescription(description); |
| | | // // 设置通知出现时的闪灯(如果Android设备支持的话)。 |
| | | // mChannel.enableLights(true); |
| | | // mChannel.setLightColor(Color.RED); |
| | | // // 设置通知出现时的震动(如果Android设备支持的话)。 |
| | | // mChannel.enableVibration(true); |
| | | // mChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400}); |
| | | // // 最后在notificationmanager中创建该通知渠道。 |
| | | // mNotificationManager.createNotificationChannel(mChannel); |
| | | // } |
| | | // } |
| | | |
| | | /** |
| | | * 重启app |