I\'ve been trying to start a service when a device boots up on android, but I cannot get it to work. I\'ve looked at a number of links online but none of the code works. Am
After trying all of mentioned answers and tricks, I finally find why the code is not work in my phone. Some Android phones like "Huawei Honor 3C Android 4.2.2" have a Statup Manager menu in their settings and your app must be checked in the list. :)
If you're using Android Studio and you're very fond of auto-complete then I must inform you, I'm using Android Studio v 1.1.0 and I used auto-complete for the following permission
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
And Android Studio Auto-completedRECEIVE_BOOT_COMPLETED
all in lower-case like receive_boot_completed
and I kept pulling my hair out because I'd already ticked out my checklist for things to do to start service at boot. I just confirmed again
Android Studio DOES auto-complete this permission in lower-case.
note that at the beginning of the question, there is a typo mistake:
<action android:name="android.intent.action._BOOT_COMPLETED"/>
instead of :
<action android:name="android.intent.action.BOOT_COMPLETED"/>
one small "_" and all this trouble :)
As an additional 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.
More details here in section Broadcast Receivers listening for "boot completed"
I found out just now that it might be because of Fast Boot
option in Settings
> Power
When I have this option off, my application receives a this broadcast but not otherwise.
By the way, I have Android 2.3.3
on HTC Incredible S
.
Hope it helps.
I faced with this problem if i leave the empty constructor in the receiver class. After the removing the empty contsructor onRreceive methos started working fine.