BOOT_COMPLETED不工作的Android [英] BOOT_COMPLETED not working Android
问题描述
首先,我知道出现了数百个这样的问题问,但我一直在检查他们的所有了一会儿,还是没找到任何解决方案。
我见过这个答案说BOOT_COMPLETED不会发送到应用程序,除非用户启动应用程序首先,安卓3.1版本后, 但我仍然看到一些应用程序在做的是,必须有一种方式。我真的需要处理它,否则我也很反对做一些事情,而无需用户的交互。
因此,这里是我的AndroidManifest:
<舱单...>
<! - 在启动被激活服务完成 - >
<使用-权限的Android:名称=android.permission.RECEIVE_BOOT_COMPLETED/>
<! - 进入休眠状态保持处理器接收到消息时。 - >
<使用-权限的Android:名称=android.permission.WAKE_LOCK/>
<应用...>
<! - 接收数据时,开机完成 - >
<接收器
机器人:名称=myPackage.BootReceiver
机器人:启用=真
机器人:出口=真
机器人:权限=android.permission.RECEIVE_BOOT_COMPLETED>
<意向滤光器>
<作用机器人:名称=android.intent.action.BOOT_COMPLETED/>
&所述; /意图滤光器>
< /接收器>
< /用途>
< /舱单>
在此先感谢。
编辑:没有太多的事情,看在我的BroadcastReceiver,但在这里需要的人,这是:
包的mypackage
公共类BootReceiver扩展的BroadcastReceiver {
@覆盖
公共无效的onReceive(上下文的背景下,意图意图){
Utils.LogI(BootReceiver,获得BootReceiver!);
如果(Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())){
//做我的东西
}
}
}
这下面的东西肯定是为我工作。
AndroidManifest.xml中
<使用-权限的Android:名称=android.permission.RECEIVE_BOOT_COMPLETED/>
<应用
>
<接收机器人:名称=。BootCompletedReceiver>
<意向滤光器>
<作用机器人:名称=android.intent.action.BOOT_COMPLETED/>
<作用机器人:名称=android.intent.action.QUICKBOOT_POWERON/>
&所述; /意图滤光器>
< /接收器>
<服务机器人:名称=NotifyingDailyService>
< /服务>
BootCompletedReceiver类
公共类BootCompletedReceiver扩展的BroadcastReceiver {
@覆盖
公共无效的onReceive(上下文的背景下,意图ARG1){
// TODO自动生成方法存根
Log.w(boot_broadcast_poc,启动服务......);
context.startService(新意图(背景下,NotifyingDailyService.class));
}
}
服务类
公共类NotifyingDailyService延伸服务{
@覆盖
公众的IBinder onBind(意向为arg0){
// TODO自动生成方法存根
返回null;
}
@覆盖
公众诠释onStartCommand(意向pIntent,诠释标志诠释startId){
// TODO自动生成方法存根
Toast.makeText(这一点,NotifyingDailyService,Toast.LENGTH_LONG).show();
Log.i(com.example.bootbroadcastpoc,NotifyingDailyService);
返回super.onStartCommand(pIntent,标志,startId);
}
}
First of all, i know there has been hundreds of this kind of question asked, but i've been checking them all for a while and still couldn't find any solution.
I've seen this answer said BOOT_COMPLETED not send to application unless user launch your application first, after Android version 3.1 But i still see some applications are doing that, there must be a way. I really need to handle it, otherwise i'm also against to do something without user's interaction.
So here's my AndroidManifest:
<manifest ... >
<!-- to be activated service on boot is completed -->
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<!-- Keeps the processor from sleeping when a message is received. -->
<uses-permission android:name="android.permission.WAKE_LOCK" />
<application ... >
<!-- to receive data when boot completed -->
<receiver
android:name="myPackage.BootReceiver"
android:enabled="true"
android:exported="true"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
</application>
</manifest>
Thanks in advance.
Edit: There is no much thing to see in my broadcastreceiver but to whom required here it is:
package myPackage
public class BootReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Utils.LogI("BootReceiver", "BootReceiver received!");
if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
// Do my stuff
}
}
}
This below thing definitely worked for me.
AndroidManifest.xml
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
>
<receiver android:name=".BootCompletedReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
</intent-filter>
</receiver>
<service android:name="NotifyingDailyService" >
</service>
BootCompletedReceiver class
public class BootCompletedReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent arg1) {
// TODO Auto-generated method stub
Log.w("boot_broadcast_poc", "starting service...");
context.startService(new Intent(context, NotifyingDailyService.class));
}
}
Service class
public class NotifyingDailyService extends Service {
@Override
public IBinder onBind(Intent arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public int onStartCommand(Intent pIntent, int flags, int startId) {
// TODO Auto-generated method stub
Toast.makeText(this, "NotifyingDailyService", Toast.LENGTH_LONG).show();
Log.i("com.example.bootbroadcastpoc","NotifyingDailyService");
return super.onStartCommand(pIntent, flags, startId);
}
}
这篇关于BOOT_COMPLETED不工作的Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!