重启后的Android通知 [英] android notification after reboot
问题描述
我想放一个通知,将推出我的应用程序时,pressed通知栏。虽然我没有问题这样做,我的用户希望通知重新启动后都好了。他们有从其他供应商,这是否一个应用程序。
I want to put up a notification in the notification bar that will launch my app when pressed. While I have no problems doing this, my users want the notification to come up after a reboot as well. They have an app from another vendor that does this.
一切我能找到该应用程序必须运行的通知显示状态。任何想法?
Everything I can find states that the app must be running for the notification to display. Any ideas?
推荐答案
您需要添加一个接收器,重新启动后启动服务。
You need to add a receiver that launches a Service after a reboot.
在您的清单寄存器引导完成
In your manifest register for Boot Complete
<service android:name="com.meCorp.service.MeCorpServiceClass"/>
...
<receiver android:name="com.meCorp.receiver.MyRebootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
...
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
在你的启动接收器,发射服务。
In your boot receiver, launch a service.
public class MyRebootReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Intent serviceIntent = new Intent(context, MeCorpServiceClass.class);
serviceIntent.putExtra("caller", "RebootReceiver");
context.startService(serviceIntent);
}
}
下面是一个服务类在后台运行的一个例子。
Here is an example for a service class to run in the background.
public class MeCorpServiceClass extends IntentService{
@Override
protected void onHandleIntent(Intent intent){
String intentType = intent.getExtras().getString("caller");
if(intentType == null) return;
if(intentType.Equals("RebootReceiver"))
//Do reboot stuff
//handle other types of callers, like a notification.
}
}
或只是使用第三方像城市的飞艇,它能够处理所有你。
OR Just use a third party like Urban AirShip, which handles all that for you.
这篇关于重启后的Android通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!