How to start android service on installation

2019-01-02 20:27发布

I have a device management application, which essentially runs as a service in the background from boot. I'd like to start this application immediately after installation. How do I achieve this?

标签: android
2条回答
与风俱净
2楼-- · 2019-01-02 21:07

You cannot do this -- there is no way to automatically start your service merely because it was installed.

The application must first be invoked by the user through some sort of activity. Or, you are going to need to hook into some relevant broadcast Intent via the manifest, so you can get control when one of those events occur and kick off your service that way. Or, you are going to need to ask the user to reboot so your BOOT_COMPLETED Intent filter can get control.

查看更多
与风俱净
3楼-- · 2019-01-02 21:26

There was a hole - the Android Analytics SDK used to send an intent right after installation - but that got closed (producing lots of confusion, of course).

But the final answer, I believe, is here:

http://developer.android.com/about/versions/android-3.1.html#launchcontrols

This seems to suggest that, as of 3.1, Google made the decision that apps are in a stopped state until the user explicitly activates them, e.g. by launching app or placing widget.

This means that the strategy of listening of a common broadcast (i.e. to get your app launched surreptitiously) won't work either.

查看更多
登录 后发表回答