| | |
| | | import com.hdl.photovoltaic.config.UserConfigManage; |
| | | import com.hdl.photovoltaic.enums.MessageStateType; |
| | | import com.hdl.photovoltaic.other.HdlPushLogic; |
| | | import com.hdl.photovoltaic.push.CustomNotification; |
| | | import com.hdl.photovoltaic.push.PushMessageInfoBean; |
| | | import com.hdl.photovoltaic.ui.BPowerStationActivity; |
| | | import com.hdl.photovoltaic.ui.StartActivity; |
| | |
| | | */ |
| | | @Override |
| | | public void onMessageReceived(RemoteMessage remoteMessage) { |
| | | Log.d(TAG, "在前台还是在后" + isAppInForeground(this)); |
| | | Log.d(TAG, "是否在前台:" + isAppInForeground(this)); |
| | | Log.d(TAG, "来自RemoteMessage: " + JSON.toJSONString(remoteMessage)); |
| | | // // 数据消息:任何状态都会执行 |
| | | // if (!remoteMessage.getData().isEmpty()) { |
| | |
| | | // if (remoteMessage.getNotification() != null) { |
| | | // handleNotification(remoteMessage.getNotification()); // 只有前台执行 |
| | | // } |
| | | |
| | | |
| | | String title = "";//推送标题 |
| | | String content = "";//推送内容 |
| | | if (remoteMessage.getNotification() != null) { |
| | | title = remoteMessage.getNotification().getTitle(); |
| | | content = remoteMessage.getNotification().getBody(); |
| | | } |
| | | //原生在前台或者uni在前台 |
| | | if (isAppInForeground(this) || HDLUniMPSDKManager.getInstance().showUniMP()) { |
| | | // 检查消息是否包含数据负载 |
| | | if (!remoteMessage.getData().isEmpty()) { |
| | | PushMessageInfoBean pushMessageInfoBean = HdlPushLogic.getInstance().pushDataProcessing(title, content, JSON.toJSONString(remoteMessage.getData())); |
| | | HdlPushLogic.getInstance().PushPushCommonData(this, pushMessageInfoBean, false); |
| | | // this.showCustomNotification(pushMessageInfoBean); |
| | | } |
| | | } else { |
| | | // 检查消息是否包含通知负载 |
| | | if (!remoteMessage.getData().isEmpty()) { |
| | | PushMessageInfoBean pushMessageInfoBean = HdlPushLogic.getInstance().pushDataProcessing(title, content, JSON.toJSONString(remoteMessage.getData())); |
| | | this.showCustomNotification(pushMessageInfoBean); |
| | | } |
| | | if (!remoteMessage.getData().isEmpty()) { |
| | | CustomNotification.getInstance().messageDataProcessing(this, title, content, JSON.toJSONString(remoteMessage.getData()), CustomNotification.FromPush.FCM); |
| | | } |
| | | // //原生在前台或者uni在前台 |
| | | // if (isAppInForeground(this)) { |
| | | // // 检查消息是否包含数据负载 |
| | | // if (!remoteMessage.getData().isEmpty()) { |
| | | // PushMessageInfoBean pushMessageInfoBean = HdlPushLogic.getInstance().pushDataProcessing(title, content, JSON.toJSONString(remoteMessage.getData())); |
| | | // HdlPushLogic.getInstance().PushPushCommonData(this, pushMessageInfoBean, false); |
| | | //// this.showCustomNotification(pushMessageInfoBean); |
| | | // } |
| | | // } else { |
| | | // // 检查消息是否包含通知负载 |
| | | // if (!remoteMessage.getData().isEmpty()) { |
| | | // PushMessageInfoBean pushMessageInfoBean = HdlPushLogic.getInstance().pushDataProcessing(title, content, JSON.toJSONString(remoteMessage.getData())); |
| | | // this.showCustomNotification(pushMessageInfoBean); |
| | | // } |
| | | // } |
| | | } |
| | | |
| | | |
| | |
| | | return false; |
| | | } |
| | | final String packageName = context.getPackageName(); |
| | | final String uniPackageName = packageName + ":unimp0"; |
| | | for (ActivityManager.RunningAppProcessInfo appProcess : appProcesses) { |
| | | if (appProcess.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND && |
| | | appProcess.processName.equals(packageName)) { |
| | | if ((appProcess.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND && |
| | | appProcess.processName.equals(packageName)) || (appProcess.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND && |
| | | appProcess.processName.equals(uniPackageName))) { |
| | | return true; |
| | | } |
| | | } |