【发布时间】:2019-06-15 09:22:57
【问题描述】:
以下是我的 Android API 级别大于 8 的待处理意图代码:
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 以下运行良好,最近我的设备更新为 pie(Android 版本 9),呈现通知,点击时我看到启动活动附加内容为null。
无论后台或前台的应用程序如何,我都会将requestMoneyData 设为null,并且在调试时我将附加内容视为“空包裹”,这仅发生在 Android 版本 9 中,并且在 Android 9 以下版本中运行良好。
感谢任何帮助解决上述问题。
【问题讨论】:
-
你能粘贴获取活动的意图代码吗?
-
捆绑附加服务 = activity.getIntent().getExtras(); if (extras != null) { requestData = (RequestData) extras.getSerializable("requestNotifyData"); }
-
您是否尝试在该活动中获得额外的使用意图?
-
是的,不工作
-
在 oncreate 方法中启动活动时 onCreate(Bundle savedInstanceState) 我将 savedInstanceState 设为 null
标签: java android android-9.0-pie