diff --git a/app/src/main/java/com/shayu/phonelive/utils/CustomMessageReceiver.java b/app/src/main/java/com/shayu/phonelive/utils/CustomMessageReceiver.java index e5776571b..21dd5926c 100644 --- a/app/src/main/java/com/shayu/phonelive/utils/CustomMessageReceiver.java +++ b/app/src/main/java/com/shayu/phonelive/utils/CustomMessageReceiver.java @@ -196,7 +196,12 @@ public class CustomMessageReceiver extends PushMessageReceiver { Intent intent = new Intent(context, MainActivity.class); intent.putExtra("type", "2"); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); - PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); + PendingIntent pendingIntent; + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) { + pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_IMMUTABLE); + }else { + pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); + } String channelId = createNotificationChannel(context, "my_channel_ID", "my_channel_NAME", NotificationManager.IMPORTANCE_HIGH); // 构建 remoteView RemoteViews remoteView = new RemoteViews(context.getPackageName(), R.layout.notification_message); @@ -225,7 +230,12 @@ public class CustomMessageReceiver extends PushMessageReceiver { intent.setFlags(FLAG_ACTIVITY_CLEAR_TOP); intent.putExtra("liveid", message.getLiveuid()); Log.e("gmc", message.getLiveuid() + "21121"); - PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); + PendingIntent pendingIntent; + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) { + pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_IMMUTABLE); + }else { + pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); + } String channelId = createNotificationChannel(context, "my_channel_ID", "my_channel_NAME", NotificationManager.IMPORTANCE_HIGH); // 构建 remoteView RemoteViews remoteView = new RemoteViews(context.getPackageName(), R.layout.notification_message); @@ -263,7 +273,12 @@ public class CustomMessageReceiver extends PushMessageReceiver { intent.putExtra("activityUrl", message.getActivityurl()); } intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); - PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); + PendingIntent pendingIntent; + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) { + pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_IMMUTABLE); + }else { + pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); + } String channelId = createNotificationChannel(context, "my_channel_ID", "my_channel_NAME", NotificationManager.IMPORTANCE_HIGH); // 构建 remoteView RemoteViews remoteView = new RemoteViews(context.getPackageName(), R.layout.notification_message);