Android - Set notification to never go away

谁说我不能喝 提交于 2019-12-06 04:20:52

If you want to print notification when the device boots up, you can create a receiver that is invoked when the system boot is completed, for 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 invoked when the system boot is completed. You can also call a service from the onReceive method of receiver to print the notification.

Also you must define the following regularities in your manifest file,

First define permission for getting BOOT_COMPLETION intent,

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

Then define your receiver also,

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

No. I don't think that is possible.

You could have a service that runs at start-up to to bring up that notification again. Notifications otherwise do not persist across reboots.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!