是android.permission.RECEIVE_BOOT_COMPLETED不需要?不需要、android、permission、RECEIVE_BOOT_COMPLETED

2023-09-04 09:48:35 作者:主宰稳场

有谁知道为什么我的申请仍然收到ACTION_BOOT_COMPLETED广播,即使我的应用程序没有在清单文件的权限 android.permission.RECEIVE_BOOT_COMPLETED ?我认为这是必需的,但一些教程我也用没了。有几个做到了。我用我的手机上运行的CyanogenMod进行测试,但我怀疑的问题。 LogCat中显示了我的通知启动的日志每次开机时。请参阅下面的使用code。

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中

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>

AlarmReceiver类

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();
     }
    }
  }

我重新审视这个仿真器上,并成功地在Android 2.1,2.2和2.3重现了问题。我得到一个ANR(如预期),因为仿真器不具备的数据库我的应用程序查询。当我删除从清单中的所有声明的用途,权限,我试图用我的应用程序时,你得到预期的许可拒绝的错误。不过,我还是收到ACTION_BOOT_COMPLETED意图在启动时播放。有什么建议?

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?

推荐答案

这似乎是在Android中的一个错误。我可以重现普通的Nexus One和Nexus S的硬件问题。我已经提交了一份 bug报告的就可以了。

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.