From 0f236f743df631c9eae47cfb743034d631684bce Mon Sep 17 00:00:00 2001 From: zlzw <583819556@qq.com> Date: Thu, 27 Oct 2022 10:34:15 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=87=A0=E5=A4=84PendingInte?= =?UTF-8?q?nt=E7=9A=84Flag=E9=97=AA=E9=80=80=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../utils/CustomMessageReceiver.java | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) 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);