|
|
@@ -54,7 +54,7 @@ public class SheepJpushReceiver extends BroadcastReceiver {
|
|
|
|
|
|
} else if (JPushInterface.ACTION_MESSAGE_RECEIVED.equals(intent.getAction())) {//自定义消息中有自定义字段时才会接收到,且不会有通知
|
|
|
Log.d(TAG, "[SheepJpushReceiver] 接收到推送下来的自定义消息: " + bundle.getString(JPushInterface.EXTRA_MESSAGE));
|
|
|
- processCustomMessage(context, intent);
|
|
|
+ PushMessageService.runIntentInService(context, intent);
|
|
|
|
|
|
} else if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(intent.getAction())) {//除了自定义消息中有自定义字段的消息,都会接收到通知
|
|
|
Log.d(TAG, "[SheepJpushReceiver] 接收到推送下来的通知");
|
|
|
@@ -116,100 +116,4 @@ public class SheepJpushReceiver extends BroadcastReceiver {
|
|
|
return sb.toString();
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 处理自定义消息
|
|
|
- * @param context
|
|
|
- * @param intent
|
|
|
- * @throws JSONException
|
|
|
- */
|
|
|
- private void processCustomMessage(Context context, Bundle bundle, int msgId) throws JSONException {
|
|
|
-// JSONObject json = new JSONObject(bundle.getString(JPushInterface.EXTRA_EXTRA));
|
|
|
-// String msg = json.optString("msg");
|
|
|
-// String title = json.optString("title");
|
|
|
-// String id = "my_channel_01";
|
|
|
-// String name = context.getString(R.string.app_name);
|
|
|
-// NotificationManager notificationManager = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);
|
|
|
-// if(notificationManager != null) {
|
|
|
-// NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context, id)
|
|
|
-// .setContentTitle(title)
|
|
|
-// .setContentText(msg);
|
|
|
-// Notification notification;
|
|
|
-// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
|
-// NotificationChannel mChannel = new NotificationChannel(id, name, NotificationManager.IMPORTANCE_HIGH);
|
|
|
-// notificationManager.createNotificationChannel(mChannel);
|
|
|
-// } else {
|
|
|
-// notificationBuilder.setOngoing(true);
|
|
|
-// }
|
|
|
-// notification = notificationBuilder.build();
|
|
|
-// notificationManager.notify(msgId, notification);
|
|
|
-// }
|
|
|
- NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
|
|
- if (mNotificationManager != null) {
|
|
|
- String appName = context.getString(R.string.app_name);
|
|
|
- String summaryText = "来自"+appName;
|
|
|
- JSONObject json = new JSONObject(bundle.getString(JPushInterface.EXTRA_EXTRA));
|
|
|
- String msg = json.optString("msg");
|
|
|
- String title = json.optString("title");
|
|
|
- //为了版本兼容 选择V7包下的NotificationCompat进行构造
|
|
|
- NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context, String.valueOf(msgId));
|
|
|
- //点击通知栏跳转到相应的应用里面
|
|
|
- Intent notificationIntent = new Intent(context, MiddleAct.class);
|
|
|
- notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
|
|
- notificationIntent.putExtras(bundle);
|
|
|
-
|
|
|
- PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
|
|
-
|
|
|
- notificationBuilder
|
|
|
- //下拉显示的大图标
|
|
|
- // .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), SkinUtil.getAppIcon()))
|
|
|
- // .setSmallIcon(R.mipmap.remenyx)//系统状态栏显示的小图标 remenyx
|
|
|
- .setSmallIcon(SkinUtil.getAppIcon())
|
|
|
- .setTicker(title)
|
|
|
- .setDefaults(Notification.DEFAULT_VIBRATE)
|
|
|
- .setWhen(System.currentTimeMillis())
|
|
|
- .setTicker(title)//Ticker是状态栏显示的提示
|
|
|
- .setDefaults(NotificationCompat.DEFAULT_ALL);
|
|
|
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
|
- notificationBuilder.setContentTitle(title)//第一行内容 通常作为通知栏标题
|
|
|
-// .setOngoing(true)//禁止滑动删除
|
|
|
- .setContentText(msg);//第二行内容 通常是通知正文
|
|
|
- NotificationChannel channel = new NotificationChannel(String.valueOf(msgId), appName, NotificationManager.IMPORTANCE_HIGH);
|
|
|
- channel.canBypassDnd();//是否可以绕过请勿打扰模式
|
|
|
- channel.canShowBadge();//是否可以显示icon角标
|
|
|
- channel.enableLights(true);//是否显示通知闪灯
|
|
|
- channel.enableVibration(true);//收到小时时震动提示
|
|
|
- channel.setBypassDnd(true);//设置绕过免打扰
|
|
|
- channel.setLockscreenVisibility(NotificationCompat.VISIBILITY_SECRET);
|
|
|
- channel.setLightColor(context.getColor(R.color.theme_app_main));//设置闪光灯颜色
|
|
|
- channel.getAudioAttributes();//获取设置铃声设置
|
|
|
- channel.setVibrationPattern(new long[]{100, 200, 100});//设置震动模式
|
|
|
- channel.shouldShowLights();//是否会闪光
|
|
|
- mNotificationManager.createNotificationChannel(channel);
|
|
|
- } else if(BuildConfig.DEBUG) {
|
|
|
- notificationBuilder.setContentTitle(title)//第一行内容 通常作为通知栏标题
|
|
|
- .setContentText(msg);//第二行内容 通常是通知正文
|
|
|
- } else {//下面部分为测试部分
|
|
|
- notificationBuilder.setContentTitle(appName)//第一行内容 通常作为通知栏标题
|
|
|
- .setContentText(title);//第二行内容 通常是通知正文
|
|
|
- if (!TextUtils.isEmpty(msg)) {
|
|
|
- notificationBuilder.setSubText(msg);//第三行内容 通常是内容摘要什么的 在低版本机器上不一定显示
|
|
|
- notificationBuilder.setStyle(new NotificationCompat.BigTextStyle().setBigContentTitle(title).setSummaryText(summaryText).bigText(msg));
|
|
|
- } else {
|
|
|
- // notificationBuilder.setSubText("subText");
|
|
|
- //添加宽视图
|
|
|
- NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle();
|
|
|
- style.setBigContentTitle(title);
|
|
|
- //由手机屏幕像素决定显示多少
|
|
|
- // style.addLine("line1");
|
|
|
- // style.addLine("line2");
|
|
|
- style.setSummaryText(summaryText);//添加概要
|
|
|
- notificationBuilder.setStyle(style);
|
|
|
- }
|
|
|
- }
|
|
|
- notificationBuilder.setPriority(Notification.PRIORITY_MAX).setContentIntent(pendingIntent);//点击跳转的intent
|
|
|
- Notification notification = notificationBuilder.build();
|
|
|
- notification.flags |= Notification.FLAG_AUTO_CANCEL;
|
|
|
- mNotificationManager.notify(msgId, notification);
|
|
|
- }
|
|
|
- }
|
|
|
}
|