我尝试了 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 添加 Action :intent.setAction("dummy");
2) 将 setClass 添加到 Intent: .setClass(this, LoginActivity.class);
3)待定 Intent 尝试了所有标志:PendingIntent.FLAG_UPDATE_CURRENT/FLAG_CANCEL_CURRENT/FLAG_ONE_SHOT/0
4) 尝试在“onNewIntent”和“onCreate”中接收额外内容
接收 Activity 中的额外内容总是错误的
@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)
关于来自待处理 Intent 的 Android bundle 始终接收为 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39372978/