修复几处PendingIntent的Flag闪退问题

This commit is contained in:
zlzw 2022-10-27 10:34:15 +08:00
parent 1d8cdf250d
commit 0f236f743d

View File

@ -196,7 +196,12 @@ public class CustomMessageReceiver extends PushMessageReceiver {
Intent intent = new Intent(context, MainActivity.class); Intent intent = new Intent(context, MainActivity.class);
intent.putExtra("type", "2"); intent.putExtra("type", "2");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 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); String channelId = createNotificationChannel(context, "my_channel_ID", "my_channel_NAME", NotificationManager.IMPORTANCE_HIGH);
// 构建 remoteView // 构建 remoteView
RemoteViews remoteView = new RemoteViews(context.getPackageName(), R.layout.notification_message); 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.setFlags(FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("liveid", message.getLiveuid()); intent.putExtra("liveid", message.getLiveuid());
Log.e("gmc", message.getLiveuid() + "21121"); 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); String channelId = createNotificationChannel(context, "my_channel_ID", "my_channel_NAME", NotificationManager.IMPORTANCE_HIGH);
// 构建 remoteView // 构建 remoteView
RemoteViews remoteView = new RemoteViews(context.getPackageName(), R.layout.notification_message); 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.putExtra("activityUrl", message.getActivityurl());
} }
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 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); String channelId = createNotificationChannel(context, "my_channel_ID", "my_channel_NAME", NotificationManager.IMPORTANCE_HIGH);
// 构建 remoteView // 构建 remoteView
RemoteViews remoteView = new RemoteViews(context.getPackageName(), R.layout.notification_message); RemoteViews remoteView = new RemoteViews(context.getPackageName(), R.layout.notification_message);