当关闭诸如Spotify之类的应用时,通知的清洁程度如何?

时间:2018-10-11 18:12:02

标签: 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));

1 个答案:

答案 0 :(得分:0)

在您活动的onDestroy()中调用它:

NotificationManager ntfManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
ntfManager.cancelAll();