2011-01-08 92 views
4

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

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类

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意图。有什么建议么?

+0

“我用我的手机运行CyanogenMod进行测试,但我怀疑这个问题” - 不要那么确定。总是对至少一个运行Android的仿真器测试这种异常情况,以确认它不是该ROM的东西。这不是敲响Cyanogen - 如果您在HTC或摩托罗拉设备上出现相同症状,我会提出相同的建议。 – CommonsWare 2011-01-08 19:09:11

+0

@CommonsWare:真的。不幸的是,我的应用使用了仿真器中不可用的功能。我会借用某人的设备继续尝试排除当前的环境。感谢您的建议。 – capitalf 2011-01-08 21:53:06

回答

7

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

相关问题