通知状态栏的活动意图?
我正在尝试从通知栏启动一个活动,但它需要获取一个整数。从一个活动到另一个活动,我只需将一个 int 放入意图中,但我似乎无法弄清楚在哪里为通知栏添加额外的内容?这可能吗?如果没有,有更好的方法吗?
public void notifyMe() {
int icon = android.R.drawable.presence_away;
CharSequence tickerText = "New Task Availible";
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, when);
Context context = getApplicationContext();
CharSequence contentTitle = "PRISM Task";
CharSequence contentText = "New Task Availible";
Intent notificationIntent = new Intent(this, TextAnswerActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notificationIntent.putExtra("taskId", 20); //unable to retrieve 20 later
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
final int HELLO_ID = 1;
mNotificationManager.notify(HELLO_ID, notification);
}
我如何检索:
Intent myIntent = getIntent();
System.out.println("#######TaskID from Intent ===== " + myIntent.getIntExtra("taskId", -1));
I am trying to start an activity from the notification bar but it needs to get an int. From activity to activity I would just put an int into the intent but I can't seem to figure out where to add the extra for the notification bar? Is this possible? If not is there a better way to do it?
public void notifyMe() {
int icon = android.R.drawable.presence_away;
CharSequence tickerText = "New Task Availible";
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, when);
Context context = getApplicationContext();
CharSequence contentTitle = "PRISM Task";
CharSequence contentText = "New Task Availible";
Intent notificationIntent = new Intent(this, TextAnswerActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notificationIntent.putExtra("taskId", 20); //unable to retrieve 20 later
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
final int HELLO_ID = 1;
mNotificationManager.notify(HELLO_ID, notification);
}
How I am retrieving:
Intent myIntent = getIntent();
System.out.println("#######TaskID from Intent ===== " + myIntent.getIntExtra("taskId", -1));
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在创建以 notificationIntent 作为参数的 PendingIntent 之前,您必须调用 notificationIntent.putExtras(...) 。试试这个代码:
并接收数据:
You have to call notificationIntent.putExtras(...) before creating PendingIntent that takes notificationIntent as a parameter. Try this code out:
And to receive the data: