How can I discover that my device has rebooted, given that HONEYCOMB BOOT COMPLETED is no longer supported?

大憨熊 提交于 2019-11-30 21:15:36

问题


I am developing app in Android 4.0.3. I've read that the HONEYCOMB BOOT COMPLETED event is no longer supported, according to Google's documentation.

Given this, how can I discover that my device has rebooted?

CODE -

Java Class :-

public class MyStartupIntentReceiver extends BroadcastReceiver{

    @Override
    public void onReceive(Context context, Intent intent) {
        Logger.i("Device", "REBOOT");
        Logger.i("Device", "REBOOT");
        Logger.i("Device", "REBOOT");
        Logger.i("Device", "REBOOT");
        Logger.i("Device", "REBOOT");
    }
}

Manifest File :-

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

<receiver android:name="MyStartupIntentReceiver" >
    <intent-filter>
       <action android:name="android.intent.action.BOOT_COMPLETED" />
       <category android:name="android.intent.category.HOME" />
    </intent-filter>
</receiver>

回答1:


sorry , but perhaps you are wrong about the documentation , any way make sure that you are including <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/> permission in your manifest . I use this broadcast in many apps and they works great.

Make sure you know aslo about this info BOOT_COMPLETE is sent to applications before external storage is mounted. So if application is installed to external storage it won't receive BOOT_COMPLETE broadcast message.




回答2:


I am developing app in Android 4.0.3. I've read that the HONEYCOMB BOOT COMPLETED event is no longer supported, according to Google's documentation.

You misinterpreted the documentation. BOOT_COMPLETED is supported. However, it does require some component of your application to be run manually, before any registered BroadcastReceiver will work. Typically, this is done by starting an activity. Hence, if you just install an app and restart the device, you will not get control at boot time.

You can read more about this in the "Launch controls on stopped applications" of the Android 3.1 release notes, as well as in this blog post.



来源:https://stackoverflow.com/questions/14108996/how-can-i-discover-that-my-device-has-rebooted-given-that-honeycomb-boot-comple

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!