Search code examples
androidandroid-manifestbootcompleted

android: use Intent.ACTION_BOOT_COMPLETED or ...?


In the AndroidManifest file, I want to capture the BOOT_COMPLETED event when the user re-boots their device. I am adding this permission:

"uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"

I have seen two "intent-filters" used by others on Stackoverflow:

"Intent.ACTION_BOOT_COMPLETED" and

"android.intent.action.BOOT_COMPLETED"

What is the preferred action string here? Please advise and explain.


Solution

  • Intent.ACTION_BOOT_COMPLETED == android.intent.action.BOOT_COMPLETED

    They're both the same, because if you look into what the value of Intent.ACTION_BOOT_COMPLETED is, you'll see that it's android.intent.action.BOOT_COMPLETED.

    Typically in the Manifest, you'll use android.intent.action.BOOT_COMPLETED due to Intent.ACTION_BOOT_COMPLETED being Java code rather than xml.

    But in your code, you can use Intent.ACTION_BOOT_COMPLETED as an alternative due to it being much easier to remember.