android - 关闭像Spotify这样的应用程序时通知有多干净?
问题描述
我有一个广播服务,它显示一个通知来识别停止和播放,但是当我通过滑动杀死应用程序时,我无法清除通知
PendingIntent openAppIntent = PendingIntent.getActivity(RadioService.this, 0, new Intent(RadioService.this, GeneralActivity.class), 0);
Notification notification = new NotificationCompat.Builder(RadioService.this)
.setSmallIcon(R.drawable.ic_pause_lx)
.setContentTitle(getResources().getString(R.string.radio) + " " + getResources().getString(R.string.app_name))
.setAutoCancel(true)
.setContentIntent(openAppIntent)
.addAction(android.R.drawable.ic_media_pause, getString(R.string.stop), PendingIntent.getBroadcast(RadioService.this, 0, new Intent(ACTION_PAUSE), 0))
.addAction(0, getString(R.string.open), openAppIntent)
.build();
mNotificationManager.notify(NOTIFICATION_ID, notification);
registerReceiver(mActionsReceiver, new IntentFilter(ACTION_PAUSE));
解决方案
在你的活动中调用它onDestroy()
:
NotificationManager ntfManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
ntfManager.cancelAll();
推荐阅读
- amazon-dynamodb - DynamoDB 二级索引不唯一?
- java - Jackson 不接受 @XlmElement 大写键
- doctrine-orm - 教义中多对多关系的清洁方式
- python - 图像处理的随机采样
- ruby - 我可以在厨师节点属性数组上使用 sort 和 uniq 吗?
- r - 关于 R 的问题:使相等的值在数据集中唯一
- android - Firebase getChildrenCount() 显示 0
- javascript - 如何使用 Keycloak 登录进行反应?
- python-3.x - 导入如何在 Spyder IDE 中工作?为什么从 Powershell 运行代码会有所不同?
- python - UnboundLocalError:分配前引用的局部变量日期