来自Pending Intent的Android Bundle始终为空。

4

我尝试了stackoverflow上提供的所有方法,但都没有帮助。

通知本身很好用,只是它不知何故丢失了它的bundle。

这里是我的PendingIntent:

 NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);

            Intent intent = new Intent(this, LoginActivity.class);
         //   Intent intent = new Intent().setClass(this, LoginActivity.class);
            intent.putExtra(Constants.KEY_BUNDLE_MESSAGE_FROM_NOTIFICATION,true);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);


            //intent.setAction("dummy");

            PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

            NotificationCompat.Builder noBuilder = new NotificationCompat.Builder(this)
                    .setSmallIcon(R.mipmap.ic_launcher)
                    .setContentTitle(title)
                    .setContentText(text)
/*                    .setStyle(new NotificationCompat.BigTextStyle()
                            .bigText(message))*/
                    .setAutoCancel(true)
                    .setContentIntent(contentIntent);

            notificationManager.notify(0, noBuilder.build());

1) 给Intent添加操作:intent.setAction("dummy");

2) 给Intent添加setClass: .setClass(this, LoginActivity.class);

3) 尝试使用所有标志的PendingIntent:PendingIntent.FLAG_UPDATE_CURRENT / FLAG_CANCEL_CURRENT / FLAG_ONE_SHOT/ 0

4) 在"onNewIntent"和"onCreate"中尝试接收extras

接收活动中的extras始终为false

 @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        Log.d(TAG, "im in login from notification!   "+ intent.hasExtra(Constants.KEY_BUNDLE_MESSAGE_FROM_NOTIFICATION));
    }


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);

    Intent intent = getIntent();
    Log.d(TAG, "im in login from notification!   "+ intent.hasExtra(Constants.KEY_BUNDLE_MESSAGE_FROM_NOTIFICATION));

有什么想法吗?谢谢!


onNewIntent 中添加:setIntent(intent) - Mark
始终在日志中看到false。 - Marv1n
你的代码看起来都很好。请发布清单。 - David Wasser
1个回答

0
onNewIntent 中添加:setIntent(intent)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接