Android - How to receive the BOOT signal with an application installed on sdcard?

爱⌒轻易说出口 提交于 2019-12-22 16:44:23

问题


I need to start a notification service for an application when the device boots. I have implemented a BroadcastReceiver that listens to the boot signal in order to start the service.

However, this works only if the application is not installed on sdcard (because the signal is received before the sdcard is mounted). Is there any solution to keep installing the application on sdcard and yet still receive that signal?

Any hack for this?

Let me know!

Thanks!


回答1:


You could either:

  1. Register an account in the AccountManager and set up a sync service (tutorial1, tutorial2) -- Android will start your service automatically; or
  2. Listen for some other broadcasts as well (such as screen off / screen on) and test whether you need to start your notification service or not.

I realize these are not easy / convenient solutions, but they're the only ones I can think of. If anyone knows a better solution, I'll be happy to upvote :).

Another solution (which could eventually be used in conjunction with one of the above) is to start your service (or check if it needs to be started) when your application is launched from the application launcher (i.e. when the "main" activity is started).



来源:https://stackoverflow.com/questions/6342867/android-how-to-receive-the-boot-signal-with-an-application-installed-on-sdcard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!