有谁知道为什么即使我的应用程序android.permission.RECEIVE_BOOT_COMPLETED
在清单文件中没有权限,我的应用程序仍然会收到 ACTION_BOOT_COMPLETED 广播?我认为它是必需的,但我使用的一些教程也没有它。有几个。我使用运行 CyanogenMod 的手机进行测试,但我怀疑这是否重要。LogCat 在每次启动时显示我的“启动通知”日志。有关使用的代码,请参见下文。
AndroidManifest.xml
<receiver android:name="AlarmReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.HOME" />
</intent-filter>
</receiver>
警报接收器类
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();
}
}
}
我在模拟器上重新访问了这个,并成功地在 Android 2.1、2.2 和 2.3 上重现了“问题”。我得到了一个 ANR(如预期的那样),因为模拟器没有我的应用程序查询的数据库。当我从清单中删除所有声明的使用权限时,我会在尝试使用我的应用程序时收到预期的权限拒绝错误。但是,我仍然收到启动时广播的 ACTION_BOOT_COMPLETED 意图。有什么建议么?