我编写了一个简单的Android应用程序,显示自定义通知如下:
Context context = getApplicationContext();
NotificationManager manager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
Notification notification = new Notification( R.drawable.icon, title, System.currentTimeMillis());
Intent notificationIntent = new Intent( context, this.getClass());
notificationIntent.putExtra("com.mysecure.lastpage", "SECURECODE");
PendingIntent pendingIntent = PendingIntent.getActivity( context , 0, notificationIntent, 0);
notification.flags = notification.flags | Notification.FLAG_ONGOING_EVENT;
notification.contentView = new RemoteViews(context.getPackageName(), R.layout.notifypbar);
notification.contentIntent = pendingIntent;
notification.contentView.setTextViewText(R.id.notifypb_status_text, text);
notification.contentView.setProgressBar(R.id.notifypb_status_progress, 100, (int)(100*progress), false);
manager.notify(104, notification);
这段代码只在我的应用程序中调用一次,它显示一个带有进度条的通知(一切都正确)。
现在,当用户单击此通知时,我的应用程序会处理 onResume
事件。
public void onResume()
{
super.onResume();
// TODO: Extras è SEMPRE NULL!!! impossibile!
Intent callingintent = getIntent();
Bundle extras = callingintent.getExtras();
但是 extras 总是为 NULL!
我尝试了各种组合:
notificationIntent.putExtra("com.mysecure.lastpage", "SECURECODE");
或者Bundle extra = new Bundle();
extra.putString(key, value);
notificationIntent.putExtra(extra);
但是getIntent().getExtras()总是返回NULL。