gpt4 book ai didi

java - 当应用程序位于 Android api 28(饼图)中的前台或后台时,单击通知 "launching activity"的附加信息为空

转载 作者:太空宇宙 更新时间:2023-11-04 09:35:07 28 4
gpt4 key购买 nike

下面是我的 Android API 级别大于 8 的待处理 Intent 的代码:

Intent intent = new Intent(context, NotificationActivityBDO.class);
intent.putExtra("requestNotifyData", requestData);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

PendingIntent contentIntent =
PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);

String CHANNEL_ID = chanelID;// The id of the channel.

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
String programId = BankBrandingUtil.getProgramIdForBranding(context);
Log.d(TAG, "programId: " + programId);
icon = R.drawable.pn_icon;
CharSequence name;
name = "Transactions";// The user-visible name of the channel.
int importance = NotificationManager.IMPORTANCE_HIGH;
NotificationChannel mChannel = new NotificationChannel(CHANNEL_ID, name, importance);
mChannel.setDescription(context.getResources().getString(R.string.lbl_iap_notification_channel_desc));
getNotificationManager(context).createNotificationChannel(mChannel);
}
Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_launcher);

//Notification.Builder builder = new Notification.Builder(context);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, CHANNEL_ID);
builder.setContentIntent(contentIntent);
builder.setLargeIcon(bitmap);
builder.setSmallIcon(icon);
builder.setTicker(tickerText)
.setContentTitle(title)
.setContentText(text);
builder.setOnlyAlertOnce(true);
builder.setAutoCancel(true);
builder.setWhen(when);

Notification notification = builder.build();

notification.defaults |= Notification.DEFAULT_SOUND;
notification.defaults |= Notification.DEFAULT_VIBRATE;

Log.v(TAG, "notifiTag: " + notifiTag);
Log.v(TAG, "notifiId: " + notifiId);

getNotificationManager(context).notify(notifiTag, notifiId, notification);

NotificationActivityBDO 中,我得到的额外内容如下:

Bundle extras = activity.getIntent().getExtras();
if (extras != null) {
requestData = (RequestData) extras.getSerializable("requestNotifyData");
}

上面的代码在 8 以下运行良好,最近我的设备更新到了饼图(Android 版本 9),呈现了通知,单击后我在启动 Activity 附加项中看到为 null

无论应用程序在后台还是前台,我都会将 requestMoneyData 设为 null,并且在调试时,我将额外内容视为“空包裹”,这种情况仅发生在 Android 版本 9 中,并且在 Android 9 以下工作正常。

感谢您为解决上述问题提供任何帮助。

最佳答案

Setting extras with Bundle:
Bundle bundle = new Bundle();
bundle.putSerializable("name", requestList);
intent.putExtra("notification", bundle);

Getting extras in activity:
intent.extras.getBundle("notification").getSerializable("name")

关于java - 当应用程序位于 Android api 28(饼图)中的前台或后台时,单击通知 "launching activity"的附加信息为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56609068/

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