我知道这个问题在网站上已经被问了很多次,然而,我似乎找不到解决方案。当应用程序没有运行时,我的BOOT_COMPLETED接收器没有被调用。
清单:
<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>
启动引导接收器:
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");
}
}
}
如果应用程序正在运行,我模拟了一个电话。adb shell
am broadcast -a android.intent.action.BOOT_COMPLETED
事件接收正确,但如果应用程序被关闭,则不会接收到事件,并且在启动时也不会接收到。
我已安装该应用程序,然后启动了几次以确保其已注册。对于这个问题,我感到非常困惑,因此非常感谢任何建议。
编辑:我可以在日志中看到所有其他已关闭的应用程序(Youtube、FileObserver等)都接收到了启动完成事件,只有我的应用程序没有接收到。