[英]Android: Detect status bar notification click
When my application fires a notification i want a method to be called after the user clicks the notification 当我的应用程序触发通知时,我希望在用户单击通知后调用一个方法
This's how i create a notification : 这就是我创建通知的方式:
Intent alarmIntent = new Intent(MainActivity.this, AlarmReceiver.class);
alarmIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
Bundle bundle = new Bundle();
PendingIntent pendingIntent;
AlarmManager manager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
Date date = new Date();
bundle.putString("name", "name");
bundle.putString("body", "body");
alarmIntent.putExtras(bundle);
pendingIntent = PendingIntent.getBroadcast(MainActivity.this, 10000, alarmIntent, PendingIntent.FLAG_CANCEL_CURRENT);
manager.setExact(AlarmManager.RTC_WAKEUP, date.getTime()+5000, pendingIntent); // fire after 5 seconds of launch
So how to edit my code to achieve that .. thank you 那么如何编辑我的代码来实现这一目标..谢谢
try this code for notification 尝试此代码进行通知
for calling 打电话
notificationshow(this);
method definition 方法定义
notificationshow(Context c) {
/*********** Create notification ***********/
Intent intent = new Intent(this, act_run_ifclicknotifctn.class);
PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0);
Notification n = new Notification.Builder(this)
.setContentTitle("New Notification text title")
.setContentText("New content text")
.setSmallIcon(R.drawable.ic_launcher)
.setContentIntent(pIntent)
.setAutoCancel(true)
/*.addAction(R.drawable.ic_launcher, "Call", pIntent)
.addAction(R.drawable.ic_launcher, "More", pIntent)
.addAction(R.drawable.ic_launcher, "And more", pIntent)*/
.build();
NotificationManager NotiMgr = (NotificationManager) this
.getSystemService(NOTIFICATION_SERVICE);
NotiMgr.notify(0, n);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.