gpt4 book ai didi

android - 点击通知应用程序后未在 android 12 版本中启动?

转载 作者:行者123 更新时间:2023-12-04 23:49:25 25 4
gpt4 key购买 nike

我的应用程序使用 FCM 进行通知。当用户在 Android 12 上点击通知时,应用程序不会启动,而在较低版本上会启动。
FirebaseMessagingService 代码如下。

private RemoteViews getCustomDesign(String title, String message) {
RemoteViews remoteViews = new RemoteViews(getApplicationContext().getPackageName(), R.layout.notification_collapsed);
remoteViews.setTextViewText(R.id.collapsed_notification_title, title);
remoteViews.setTextViewText(R.id.collapsed_notification_info, message);
return remoteViews;
}

@SuppressLint("UnspecifiedImmutableFlag")
public void showNotification(Context context, NotificationData data) {
Intent intent = new Intent(context, MainActivity.class);
String channel_id = "Default";
intent.putExtra(NOTIFICATION_ID, data.getNotificationId());
intent.putExtra(LEAD_ID, data.getLeadId());
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);

PendingIntent notifyPendingIntent;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
notifyPendingIntent = PendingIntent.getActivity(context,
0, intent, PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT);

}else {
notifyPendingIntent = PendingIntent.getActivity(context,
0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
}
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, channel_id)
.setSmallIcon(R.drawable.logoo)
.setAutoCancel(true)
.setOnlyAlertOnce(true)
.setContentIntent(notifyPendingIntent)
.setColor(ContextCompat.getColor(this, R.color.colorPrimary))
.setStyle(new NotificationCompat.DecoratedCustomViewStyle())
.setCustomContentView(getCustomDesign(data.getTitle(), data.getMessage()));
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel notificationChannel = new NotificationChannel(channel_id, "Default channel", NotificationManager.IMPORTANCE_HIGH);
notificationManager.createNotificationChannel(notificationChannel);
}

notificationManager.notify(0, builder.build());
}

最佳答案

请在 build.gradle 检查您的 com.google.firebase:firebase-messaging 版本
经过数小时的搜索,我发现 Firebase 团队在 v22.0.0 中修复了它
https://firebase.google.com/support/release-notes/android#messaging_v22-0-0

关于android - 点击通知应用程序后未在 android 12 版本中启动?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70955901/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com