Android 未在设备中调用BOOT_COMPLETED

Android 未在设备中调用BOOT_COMPLETED,android,android-broadcast,android-reboot,Android,Android Broadcast,Android Reboot,我想在设备启动时启动一个alram,为此我做了以下工作 1) 用户权限 <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> 上面的代码在genymotion中工作,但在实际设备上不工作 android:name=".sms.BootReceiver" 而不是那种用途 android:name=".BootReceiver" 或 希望这能解决您的问题。问题是android:n

我想在设备启动时启动一个alram,为此我做了以下工作

1) 用户权限

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
上面的代码在genymotion中工作,但在实际设备上不工作

  android:name=".sms.BootReceiver"
而不是那种用途

android:name=".BootReceiver"


希望这能解决您的问题。

问题是
android:name=“.sms.BootReceiver”
,应该是
android:name=“.BootReceiver”
。但有些设备无法捕获
引导\u已完成
。您的
意图过滤器应如下所示:

<intent-filter>
   <action android:name="android.intent.action.BOOT_COMPLETED" />
   <action android:name="android.intent.action.QUICKBOOT_POWERON" />
   <action android:name="com.htc.intent.action.QUICKBOOT_POWERON" />
</intent-filter>

确保应用程序中至少有一个活动。从Android 3.1开始,只有用户手动启动活动,BroadcastReceiver才会工作,这是为了提供安全性。一旦用户第一次运行应用程序,您的BroadcastReceiver将始终运行,除非它不会强制停止。一旦活动在第一时间启动,您的广播接收器将运行,即使重新启动设备


在emulator上,它正在工作-这可能是因为它运行在低于3.1的版本上,而真实设备运行在高于3.1的版本上

感谢您的帮助,但最终我通过设置
android.intent.action.BOOT_完成了它的工作
android:installLocation=“internalOnly”
当启动完成时,会触发存储在内存中的应用程序。

您的设备上有自定义rom吗?如果您删除if语句并只检查是否接收到Boradcast,会怎么样?@Opiatefuchs为什么?这不是问题。只想知道BroadcastReceiver是否没有接收到或只是语句没有被激发……BroadcastReceiver没有接收到它我尝试过在重新启动后我打开了我的活动,然后再次重新启动它,但它仍然没有被调用,我的模拟器有一个4.2版本当设备重新启动时会发生什么?我已经尝试了你的方法解决方案,但只有当我的设备自动重新启动时,即当我的设备耗尽电池并关闭时,才会调用此功能。@Hunt在我看来,问题出在别处。com.htc.intent到底是什么?我已经尝试过你的解决方案,但是,只有当我的设备自动重新启动时,也就是说,当我的设备耗尽电池并关闭时,才会调用此功能
android:name=".BootReceiver"
android:name="complete.packagename.sms.BootReceiver"
<intent-filter>
   <action android:name="android.intent.action.BOOT_COMPLETED" />
   <action android:name="android.intent.action.QUICKBOOT_POWERON" />
   <action android:name="com.htc.intent.action.QUICKBOOT_POWERON" />
</intent-filter>
if ((intent.getAction().equals("android.intent.action.BOOT_COMPLETED") 
   || intent.getAction().equals("android.intent.action.QUICKBOOT_POWERON")
   || intent.getAction().equals("com.htc.intent.action.QUICKBOOT_POWERON"))){
      Toast.makeText(context, "FIRED BOOT COMPLETE" , Toast.LENGTH_LONG).show();
}
<receiver android:name="your.package.example.BootReceiver" >
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
            </intent-filter>
        </receiver>