问题描述
我知道这个问题已经被问了很多的网站上,但是,我似乎无法找到一个解决方案。当应用程序没有运行我的BOOT_COMPLETED接收器不叫。
I am aware that this question has been asked a lot on the site, however, I cant seem to find a solution. My BOOT_COMPLETED receiver is not called when the application is not running.
清单:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.startuptest"
android:versionCode="1"
android:versionName="1.0"
android:installLocation="internalOnly">
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.startuptest.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name="com.example.startuptest.StartUpBootReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
</application>
</manifest>
StartUpBootReceiver:
StartUpBootReceiver:
public class StartUpBootReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Log.d("startuptest", "StartUpBootReceiver " + intent.getAction());
if ("android.intent.action.BOOT_COMPLETED".equals(intent.getAction())) {
Log.d("startuptest", "StartUpBootReceiver BOOT_COMPLETED");
}
}
}
如果应用程序在运行,我模拟了电话
If the application is running and I simulate a call with
adb shell
am broadcast -a android.intent.action.BOOT_COMPLETED
该事件被正确地接收,然而,如果该应用程序被关闭的事件不receieved,也不是在启动时接收到的
The event is received correctly, however, if the application is closed the event is not receieved, nor is it received at start up.
我已经安装的应用程序,然后启动它几次以确保它是注册。我是pretty的失去了在这一个,所以任何建议将是非常美联社preciated。
I have installed the application then launched it a couple of times to make sure it is registered. I'm pretty lost on this one so any advice would be highly appreciated.
编辑:我可以在所有其他封闭的应用程序(YouTube上,FileObserver等)收到boot_completed事件日志中看到的,只是不是我的
I can see in the logs that all the other closed applications (Youtube, FileObserver, etc) receive the boot_completed event, just not mine.
干杯
推荐答案
我开始我的应用程序时,BOOT_COMPLETED,所以我知道它的工作。我想补充 Log.d
它不会显示。我想补充吐司
表现出来。小型动物中的Manifest.xml
I start my app when the BOOT_COMPLETED, so I know it's working. I add Log.d
it won't show. I add Toast
it show. Small differents in Manifest.xml
<receiver android:name="com.example.startuptest.StartUpBootReceiver" android:enabled="true" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
这篇关于当应用程序被关闭的Android BOOT_COMPLETED没有收到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!