How to start a Service when .apk is Installed for the first time

后端 未结 10 1769
遇见更好的自我
遇见更好的自我 2020-11-22 10:33

In my Application I am not having any UI part, so I need to start a Service as soon as the Applicaton gets installed on the Device. I saw many links from which the answer wa

10条回答
  •  深忆病人
    2020-11-22 11:09

    As stated by CommonsWare in the answer to this question (which I suppose you have all ready seen, but chose to ignore) starting a Service on install is not possible - it is simply not a thing that is implemented into the platform.

    Starting it automaticly at the next boot is however possible.

    As stated in the Technical Details for PlanB:

    Plan B will attempt to launch as soon as it downloads, but in some cases you will need to send an SMS to get it started.

    My guess is that on a rooted phone you might be able to start the Service on install - but there's no guarantee that the phone is rooted, which is why PlanB will require recieving a text in some cases because that can be registered by the IntentFilter of the app and then used to start the Service.

提交回复
热议问题