0

Notification状態に応じてステータスバーを表示しています。ここまではOKです。

アプリケーションの問題は、アプリケーションに戻ったときにまだNotificationステータスバーに表示されていることです。

Notificationアプリケーションから戻ったときはしたくありません。このために、いくつかの提案をしてください。

4

4 に答える 4

4

コメントを追加するのに十分な担当者がいないので @Commonware 。. . 通知を作成するときに「通知ID」 を使用し、そのIDを使用して通知をキャンセルするように指示するなど、より具体的な詳細を提供すると、将来の読者にとってより役立ちます 。回答する場合は、それを完全にするか、少なくとも完全な詳細を提供してください。これらの投稿は OP のためだけのものではなく、この投稿に出くわした他の人にも役立ちます。そのようです

final NotificationManager notificationManager = (NotificationManager) getSystemService (NOTIFICATION_SERVICE);

final Notification notification = new Notification(R.drawable.icon,"A New Message!",System.currentTimeMillis());

notification.defaults=Notification.FLAG_ONLY_ALERT_ONCE+Notification.FLAG_AUTO_CANCEL;
Intent notificationIntent = new Intent(this, AndroidNotifications.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,notificationIntent, 0);

notification.setLatestEventInfo(AndroidNotifications.this, title,message, pendingIntent);
notificationManager.notify(NOTIFICATION_ID, notification);

次に、それをキャンセルするには、電話します

notificationManager.cancel(NOTIFICATION_ID);

またはあなたが呼び出すことができます

notificationManager.cancelAll();
于 2013-08-21T06:03:30.223 に答える
0

を介してcancel()独自に作成できます。いつそれを表示するかを決定するのはあなた次第です。NotificationsNotificationManagercancel()

于 2010-05-14T11:52:59.407 に答える
0
notificationManager.cancelAll();
于 2014-03-13T14:13:20.657 に答える
0
private void cancelNotificationInBar() {
        NotificationCreator notification = new NotificationCreator(getApplicationContext());
        notification.mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);

        if (notification.mNotificationManager != null) {
            notification.mNotificationManager.cancelAll();
        }
    }
于 2016-08-25T11:31:37.393 に答える