Android的 - 设置通知永远不会消失 [英] Android - Set notification to never go away
问题描述
我有这样的code,它的伟大工程:
I have this code that works great:
Notification n = builder.build();
n.flags = Notification.FLAG_NO_CLEAR;
但是,当我重新启动手机,通知消失。有没有做到这一点的标志?
But when I restart the phone, the notification goes away. Is there any flag that make that happen?
推荐答案
如果您想打印通知时,该装置启动时,您可以创建在系统启动完毕时调用,这个接收器,首先创建一个接收器,
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
}
}
在完成系统启动该接收机被调用。您也可以从接收机的onReceive方法调用服务来打印通知。
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.
另外你必须在你的manifest文件定义以下规律,
Also you must define the following regularities in your manifest file,
首先定义权限获取BOOT_COMPLETION意图,
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>
这篇关于Android的 - 设置通知永远不会消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!