Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/223.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 我有一个带有附加意图的通知,我如何将数据传递给意图活动?_Android - Fatal编程技术网

Android 我有一个带有附加意图的通知,我如何将数据传递给意图活动?

Android 我有一个带有附加意图的通知,我如何将数据传递给意图活动?,android,Android,我有一份意向通知。当您单击通知时,它将启动活动,但是在MainActivity中,我不知道如何使用该意图。我还假设,一旦我知道如何读取主要活动中的意图,我就可以使用putExtra()传递数据 感谢您在您开始的活动中使用: notificationManager = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE); note = new Notification(android.R.drawable

我有一份意向通知。当您单击通知时,它将启动活动,但是在MainActivity中,我不知道如何使用该意图。我还假设,一旦我知道如何读取主要活动中的意图,我就可以使用putExtra()传递数据


感谢您在您开始的活动中使用:

notificationManager = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE);
note = new Notification(android.R.drawable.btn_star_big_on, "Ticker Text", System.currentTimeMillis() );

note.defaults |= Notification.DEFAULT_SOUND;
note.defaults |= Notification.DEFAULT_VIBRATE;
note.defaults |= Notification.FLAG_AUTO_CANCEL;

Intent notificationIntent = new Intent(ctx, com.mindfsck.PossAff.MainActivity.class);
//Intent notificationIntent = new Intent();
notificationIntent.setAction(Intent.ACTION_MAIN);
notificationIntent = notificationIntent.setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);

contentIntent = PendingIntent.getActivity(ctx, 0, notificationIntent, 0);

note.setLatestEventInfo(ctx, "contentTitle", "contentText", contentIntent);

note.number = 1;  //Just created notification so number=1. Remove this line if you dont want numbers

notificationManager.notify(notif_ID,note);

…是的,您需要使用
putExtra
将数据传递给
Intent
您在Intent中设置的额外数据必须由
getIntent()检索。
savedInsanceState
更多的是检索状态

Bundle extras = getIntent().getExtras();
if(extras !=null) {
    //read extras (extras.getString/getBoolean/etc)
}