首页 > 解决方案 > 关闭像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));

标签: androidspotify

解决方案


在你的活动中调用它onDestroy()

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

推荐阅读