Is there a unique boot session id or count on an android device?

The app I'm writing needs to know if a 'boot session', for want of a better term, has changed but it doesn't need to actually start at boot and I would prefer if possible not to have to use the RECEIVE_BOOT_COMPLETED permission.

So I was wondering if there is any device-wide boot session id or count I can query and store in my db to check against later. I know I can get the time in milliseconds since boot but I don't think that will be useful in this case.

Thanks in advance for any help.


Solution 1:

Yes, on API >= 24. You can use the BOOT_COUNT global settings variable. To read this, try a snippet like this:

int boot_count = Settings.Global.getInt(getContext().getContentResolver(),
                                        Settings.Global.BOOT_COUNT);

Pre-API 24, you're stuck catching RECEIVE_BOOT_COMPLETED.