Determine if phone has been rebooted

前端 未结 1 1229
心在旅途
心在旅途 2021-01-22 16:42

I\'m trying to detect if an Android device has rebooted since the last time a preference value is set. Ideally, I\'d like to do it without the android.permission.RECEIVE_B

相关标签:
1条回答
  • 2021-01-22 17:10

    Yes you can do that using Application class and the Non-Static broadcast Receiver ACTION_SHUTDOWN. The Application class got started in two cases

    1. Android Device Boot
    2. Your Application Starts after it was "Force-Close" it.

    When ACTION_SHUTDOWN received use your application Shared-preferences or database to save a boolean shutdown = true when application class starts check this boolean. If it is true then the device is booting , else the user forced your app to stop.

    To get more info you can read the following post that I wrote and try the code example in which, I added

    1. Application Class
    2. Boot Broadcast Receiver (To Show the difference and that both starts)
    3. Shutdown broadcast receiver that is register in the Application calss
    0 讨论(0)
提交回复
热议问题