通知栏单击以关闭应用程序 [英] Notification bar click to close app

查看:79
本文介绍了通知栏单击以关闭应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户单击通知栏中的文本而不显示任何窗口时,如何关闭应用程序?

How can I close app when user clicks on text in notification bar without displaying any window?

推荐答案

使用以下代码并在您的活动中注册广播接收器:

Use the following code and register broadcast receiver in your activity :

NotificationManager mNotificationManager = (NotificationManager)_context.getSystemService(Context.NOTIFICATION_SERVICE);   

Notification notification = new Notification(R.drawable.icon,"",System.currentTimeMillis());
notification.flags = Notification.FLAG_AUTO_CANCEL;


Context context = _context.getApplicationContext();


/** Set the intent extras to be passed to calling activity*/
Intent notificationIntent = new Intent("action_close_app");



/** Create a pending intent, requires to generate a notification */

PendingIntent contentIntent = PendingIntent.getBroadcase(
  _context.getApplicationContext(), requestCode,
  notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);


/** Set notification with required fields */

notification.setLatestEventInfo(context, "", "", contentIntent);



/** notify manager to generate notification on status bar*/

mNotificationManager.notify(NOTIFICATION_ID, notification)

这篇关于通知栏单击以关闭应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆