安卓:intent.putExtra在服务类获得通知 [英] Android: intent.putExtra in a Service Class to get notifications
本文介绍了安卓:intent.putExtra在服务类获得通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是在服务类我showNotification方法
private void showNotification() {
Notification notification = new Notification(R.drawable.icon,
"New Notification", System.currentTimeMillis());
Intent i = new Intent(this, myActivity.class);
i.putExtra("notification", "MyNotif");
i.putExtra("notifiedby", "NotedBy");
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, i, 0);
notification.setLatestEventInfo(this, "NotedBy", "MyNotif", contentIntent);
nm.notify(111, notification);
}
所以单击通知在状态栏之后,我会在最后的 myActivity
so after clicking on the Notification from the status bar, i will end up in myActivity.
问题是这些行总是给人假在myActivity。
The problem is these lines always gives false in the myActivity.
this.getIntent().hasExtra("notification")
this.getIntent().hasExtra("notifiedby")
不putExtra()与正常工作的PendingIntent ??
推荐答案
试试这个code来代替:
Try this code instead:
String notification = getIntent().getStringExtra("notification");
String notifiedby = getIntent().getStringExtra("notifiedby");
这篇关于安卓:intent.putExtra在服务类获得通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文