2014-11-06 129 views
0

我期待我的应用程序加载BroadcastReceiver AutoStartOnBoot当我重新启动我的设备。奇怪BOOT_COMPLETED行为

  1. 我卸载并安装该应用程序。这意味着所有现有设置都将被删除。然后我关掉手机。并重新启动它,广播接收器永远不会被调用。
  2. 我现在再次关闭设备电源并重新上电。但是,广播接收器不被调用。
  3. 我现在启动应用程序一次。清除数据。并关闭它。我给它启动。现在,广播接收器被调用。

清单

<receiver 
     android:name=".AutoStartOnBoot" 
     android:enabled="true" 
     android:exported="true" 
     android:permission="android.permission.RECEIVE_BOOT_COMPLETED" > 
     <intent-filter> 
      <action android:name="android.intent.action.BOOT_COMPLETED" /> 
      <action android:name="android.intent.action.QUICKBOOT_POWERON" /> 

      <category android:name="android.intent.category.DEFAULT" /> 
     </intent-filter> 
    </receiver> 

我有权限设置

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> 
+0

http://stackoverflow.com/questions/11246326/how-to-receiving-broadcast-when-application-installed-or-removed – 2014-11-06 11:19:15

回答

1

所有的答案都正确无误。这种行为符合预期。该应用程序在安装时处于非活动状态,直到由所有者手动启动。之后才是在操作系统注册的BOOT_COMPLETED广播接收器。

除非我们把应用程序在系统文件夹,保持在active状态的所有应用程序。我们是设备公司,adb push your.apk /system/app可能适用于我们。

一些有趣的链接,herehere

+2

虽然这个链接可能会回答这个问题,但最好在这里包含答案的重要部分,并提供参考链接。如果链接页面发生变化,则仅链接答案可能会失效。 – 2014-11-07 01:05:51

+0

我希望它更加准确现在,谢谢。 – Siddharth 2014-11-07 04:59:25

3

编辑:

从你的第一个两分

1.I uninstall and install the app. Which means that all existing settings are deleted. I then power down the phone. And power it back up, the Broadcast receiver is never called. 
2.I now, power down the device one more time and power it up again. Yet, broadcast receiver is not called. 

为什么它不工作?

在这里你刚刚安装的应用程序,但没有launch.In.In首次启动后,只有所有的清单数据已注册,所有接收器的工作。但在第三种情况下,它的工作,因为你是启动应用程序,所以在这里所有的接收器获得注册。

对于这里更多的检查Broadcast Receiver not working immediately after package installation

你必须在manifest文件中添加此权限<application>标签之外

,而不是这个

<android:permission="android.permission.RECEIVE_BOOT_COMPLETED" > 

添加这个喜欢

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> 
+0

我有它,<用途-permission android:name =“android.permission。RECEIVE_BOOT_COMPLETED“/> – Siddharth 2014-11-06 11:22:17

+0

@Siddharth ok ..这是什么意思,是什么意思,”当我第一次安装应用程序?“,是否在下次工作? – 2014-11-06 11:24:08

+0

澄清了我的问题 – Siddharth 2014-11-06 11:29:18

1

您描述的行为是每个很正常。有些东西需要使用明确的Intent在您的清单注册的接收器可以工作之前启动您的一个组件。通常,这将是用户在主屏幕启动器图标上点击。

有关更多信息,请参阅the Android 3.1 release notes

+0

我没有得到任何与启动有关的信息 – Siddharth 2014-11-06 15:16:25