Android: Using AUTO-CANCEL on a notification when your app is running in the background

后端 未结 3 774
猫巷女王i
猫巷女王i 2020-12-14 02:25

I have looked at all the other AUTO-CANCEL-not-working questions here, and they all seem to involve mistakes that I am not making. I have tried both

builder         


        
3条回答
  •  时光取名叫无心
    2020-12-14 03:07

    Hai dear friend if you want to show non cancelable notification(not cancelable for users) for a particular time and after that you need clear it (like the music player) you can use this.

    mNotificationBuilder .setSmallIcon(android.R.drawable.btn_plus);
    mNotificationBuilder .setContentTitle("My notification");
    mNotificationBuilder .setContentText("Notificattion From service");
    mNotificationBuilder .setLights(0xFF0000FF, 500, 500);
    
    Notification note = mNotificationBuilder.build();  
    note.flags = Notification.FLAG_ONGOING_EVENT; // For Non cancellable notification
    mNotificationManager.notify(NOTIFICATION_ID, note);
    

提交回复
热议问题