【问题标题】:on click of notification "launching activity" has extras as null, when app is in foreground or back ground in Android api 28 (pie)当应用程序在 Android api 28(饼图)中处于前台或后台时,单击通知“启动活动”时的附加信息为 null
【发布时间】: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


【解决方案1】:
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")

【讨论】:

    【解决方案2】:

    请使用发送数据

    intent.setData(Uri.parse("here url will be there"))
    

    获取数据

    final String fcm_message = intent.data.toString()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-05-21
      • 1970-01-01
      • 1970-01-01
      • 2018-07-31
      • 1970-01-01
      • 1970-01-01
      • 2020-03-22
      相关资源
      最近更新 更多