Does anyone know why my application still receives the ACTION_BOOT_COMPLETED broadcast even when my app doesn't have the permission android.permission.RECEIVE_BOOT_COMPLETED
in the manifest file? I thought it was required but a few tutorials I used also didn't have it. A few did. I use my phone running CyanogenMod for testing but I doubt that matters. LogCat shows my "Notified of boot" log upon each boot. See below for code used.
AndroidManifest.xml
<receiver android:name="AlarmReceiver">
<intent-filter>
<action android:name="android.inten开发者_JAVA百科t.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.HOME" />
</intent-filter>
</receiver>
AlarmReceiver class
public class AlarmReceiver extends BroadcastReceiver {
private static final String TAG = "MyProgram";
@Override
public void onReceive(Context context, Intent intent) {
try {
if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
Log.d(TAG, "Notified of boot");
}
Intent newIntent = new Intent(context, MyService.class);
context.startService(newIntent);
} catch (Exception e) {
Log.d(TAG, "An alarm was received but there was an error");
e.printStackTrace();
}
}
}
I revisited this on the emulator and successfully reproduced the "problem" on Android 2.1, 2.2 and 2.3. I get an ANR (as expected) since the emulator doesn't have the database my app queries. When I remove all declared uses-permissions from the manifest, I get the expected permission denial errors when trying to use my app. However, I still receive the ACTION_BOOT_COMPLETED intent broadcasted upon boot. Any suggestions?
This would appear to be a bug in Android. I can reproduce the problem on ordinary Nexus One and Nexus S hardware. I have filed a bug report on it.
精彩评论