Notification
状態に応じてステータスバーを表示しています。ここまではOKです。
アプリケーションの問題は、アプリケーションに戻ったときにまだNotification
ステータスバーに表示されていることです。
Notification
アプリケーションから戻ったときはしたくありません。このために、いくつかの提案をしてください。
Notification
状態に応じてステータスバーを表示しています。ここまではOKです。
アプリケーションの問題は、アプリケーションに戻ったときにまだNotification
ステータスバーに表示されていることです。
Notification
アプリケーションから戻ったときはしたくありません。このために、いくつかの提案をしてください。
コメントを追加するのに十分な担当者がいないので @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();
を介してcancel()
独自に作成できます。いつそれを表示するかを決定するのはあなた次第です。Notifications
NotificationManager
cancel()
notificationManager.cancelAll();
private void cancelNotificationInBar() {
NotificationCreator notification = new NotificationCreator(getApplicationContext());
notification.mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
if (notification.mNotificationManager != null) {
notification.mNotificationManager.cancelAll();
}
}