Trying to start a service on boot on Android

后端 未结 16 1475
慢半拍i
慢半拍i 2020-11-21 06:41

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

相关标签:
16条回答
  • 2020-11-21 07:09

    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. :)

    0 讨论(0)
  • 2020-11-21 07:09

    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.

    0 讨论(0)
  • 2020-11-21 07:12

    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 :)

    0 讨论(0)
  • 2020-11-21 07:13

    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"

    0 讨论(0)
  • 2020-11-21 07:14

    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.

    0 讨论(0)
  • 2020-11-21 07:15

    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.

    0 讨论(0)
提交回复
热议问题