Start android application without activity

前端 未结 3 1546
温柔的废话
温柔的废话 2020-11-30 01:24

I\'ve an application which aims to run only as a service (no interface, just run in background). I have no activity mentioned in my AndroidManifest.xml but put a receiver to

3条回答
  •  南笙
    南笙 (楼主)
    2020-11-30 02:09

    Apart from the two options mentioned by EboMike: You can always send the BOOT_COMPLETED broadcast via the command line instead of rebooting your phone.

    Use

    adb shell am broadcast -a android.intent.action.BOOT_COMPLETED
    

    This will result in a situation like after an actual reboot, and will also trigger any 3rd party apps boot receivers. After typing it once in a terminal you can usually repeat it simply by pressing the up-arrow key followed by return on most operating systems. Or you can include it in a script thats triggered after reinstalling your app.


    If you want to limit the broadcast to your app only, you can also specify a component:

    adb shell am broadcast -a android.intent.action.BOOT_COMPLETED -n your.app.packagename/.YourReceiverClassName
    

    This sends the reboot broadcast only to your receiver. All other apps are not called.

提交回复
热议问题