cap*_*alf 4 boot android broadcastreceiver
有谁知道为什么我的应用程序仍然收到ACTION_BOOT_COMPLETED广播,即使我的应用程序没有android.permission.RECEIVE_BOOT_COMPLETED清单文件中的权限?我认为这是必需的,但我使用的一些教程也没有.一些人做了.我用我的手机运行CyanogenMod进行测试,但我怀疑这很重要.LogCat在每次启动时显示我的"Notified of boot"日志.请参阅下面的代码.
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>
Run Code Online (Sandbox Code Playgroud)
AlarmReceiver类
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();
}
}
}
Run Code Online (Sandbox Code Playgroud)
我在模拟器上重新审视了这一点,并成功地重现了Android 2.1,2.2和2.3上的"问题".我得到一个ANR(如预期的那样),因为模拟器没有数据库我的app查询.当我从清单中删除所有声明的使用权限时,我在尝试使用我的应用程序时得到了预期的权限拒绝错误.但是,我仍然收到启动时广播的ACTION_BOOT_COMPLETED意图.有什么建议?
| 归档时间: |
|
| 查看次数: |
5673 次 |
| 最近记录: |