我尝试了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