How to clear notification from notification tray when clicked in nokia-x

Purpose: The notification should be automatically canceled by clicking and should open my activity (pending intent).

I have working code that works fine in Android Devices, expecting Nokia-X . Here is the code:

Notification notification = new NotificationCompat.Builder(MainActivity.this) .setContentTitle(MainActivity.this.getString(R.string.app_name)) .setContentText("text").setContentInfo("info").setTicker("Ticker text") .setContentIntent(contentIntent).setSmallIcon(R.drawable.ic_launcher).setWhen(System.currentTimeMillis()) .setLights(Color.YELLOW, 1, 2).setAutoCancel(true).build(); NotificationManager nm = (NotificationManager)MainActivity.this.getSystemService(Context.NOTIFICATION_SERVICE); nm.notify(1, notification); 

In the case of a Nokia-x device, it sends a notification. It opens my activity when I click a notification, but the notification remains in the notification tray. It does not become clear when pressed.

Please help me!

+6
source share
1 answer

This is exactly the same as Dr. Yucca said: notifications cannot be removed programmatically from Fastlane - only the user can delete content from Fastlane:

"Currently, all notifications are stored in Fastlane, even if the automatic cancel flag is used. Please note that if your notification has a visible command with which the user can delete / delete the notification manually, the notification will not be deleted from Fastlane. Notifications can only be deleted from Fastlane manually by enabling edit mode. "

In addition, it makes no sense to have elements, such as notifications, that suddenly disappear from Fastlane, since the purpose of the view is to display user / application actions in the past.

+2
source

Source: https://habr.com/ru/post/970385/


All Articles