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.
Here is a complete solution:
Set the permission in the manifest:
You need a receiver to run when your system restarts so something like this:
Include this receiver in your manifest like below:
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'sandroid.intent.action.BOOT_COMPLETED
.Typically in the Manifest, you'll use
android.intent.action.BOOT_COMPLETED
due toIntent.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.