Android - set a notification to never leave

I have this code that works fine:

Notification n = builder.build(); n.flags = Notification.FLAG_NO_CLEAR; 

But when I restart the phone, the notification disappears. Is there any flag that can happen?

+2
source share
2 answers

If you want to print a notification when the device boots, you can create a receiver that is called when the system boots up, to do this, first create a receiver,

 public class MyReciever extends BroadcastReceiver{ @Override public void onReceive(Context context, Intent intent) { Log.d("BOOT COMPLETE","SERVICE CALLED>>>>>>>>>>>>"); //use your code here to print notifications } } 

This receiver is called when the system boot is complete. You can also call the service from the onReceive method of the recipient to print a notification.

You should also identify the following patterns in your manifest file,

First, determine permission to get the intent BOOT_COMPLETION,

 <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/> 

Then determine your receiver,

  <receiver android:name=".MyReciever" android:enabled="true" android:exported="false"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED"/> </intent-filter> </receiver> 
+1
source

No. I do not think that's possible.

You may have a service that starts at startup to reopen this notification. Notifications otherwise are not saved upon reboot.

+1
source

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


All Articles