| | |
| | | } |
| | | PushMessageInfoBean pushMessageInfoBean = HdlPushLogic.getInstance().pushDataProcessing(title, content, data); |
| | | //原生在前台或者uni在前台 |
| | | if (this.isAppInForegroundOrIsShowUniMP(context)) { |
| | | HdlPushLogic.getInstance().PushPushCommonData(context, pushMessageInfoBean, false); |
| | | if (this.isAppInForeground(context)) { |
| | | HdlPushLogic.getInstance().PushPushCommonData(context, pushMessageInfoBean, true); |
| | | } else { |
| | | this.showCustomNotification(context, pushMessageInfoBean, fromPush); |
| | | } |
| | | // this.showCustomNotification(context, pushMessageInfoBean); |
| | | } |
| | | |
| | | /** |
| | | * 是否在前台 true表示在前台,false表示在后台 |
| | | * |
| | | * @param context 上下文 |
| | | * @return true表示在前台,false表示在后台 |
| | | */ |
| | | public boolean isAppInForegroundOrIsShowUniMP(Context context) { |
| | | return (this.isAppInForeground(context) || HDLUniMPSDKManager.getInstance().showUniMP()); |
| | | } |
| | | |
| | | /** |
| | | * 处理通知消息(应用在后台时,系统会自动显示通知) |
| | |
| | | |
| | | /** |
| | | * 获取Intent |
| | | * @param context 上下文 |
| | | * |
| | | * @param context 上下文 |
| | | * @param pushMessageInfoBean 数据模型 |
| | | * @param fromPush 消息来自(极光,谷歌,阿里云)平台 |
| | | * @param fromPush 消息来自(极光,谷歌,阿里云)平台 |
| | | * @return 意图 |
| | | */ |
| | | public Intent createNotificationIntent(Context context, PushMessageInfoBean pushMessageInfoBean, FromPush fromPush) { |
| | |
| | | * @param context 上下 |
| | | * @return true表示在前台,false在后台 |
| | | */ |
| | | private boolean isAppInForeground(Context context) { |
| | | public boolean isAppInForeground(Context context) { |
| | | try { |
| | | ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); |
| | | List<ActivityManager.RunningAppProcessInfo> appProcesses = activityManager.getRunningAppProcesses(); |
| | |
| | | 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; |
| | | } |
| | | } |