Search code examples
androidserviceboot

Start Service on boot without activity (but with root)


I want to create an app only for my phone, that runs all the time in background - and you should never stop that service from running. My goal is, that this app is sending the current location data to my computer at home - to get it back, when it has been stolen for example, or when I lost it.

The problem is, that it is not possible to start a service without having an activity and/or launcher icon (because the thief should not know this).

But: My phone is rooted, so is it possible to start the service anyway?

And also: When I place my APK into the /system/app partition, will the APK persist after doing a factory reset?


Solution

  • Yes, you can. Rooting your phone doesn't matter for what you want to do, and if anyone tried to factory reset your phone, your app will still not be deleted, if you put your apk in /system/app partition as you said. It will react as if it was a normal system app. But of course, you must also set the correct permissions for your app when moving it to the system folder to be able to work.

    And to prevent the thief from knowing your app, you can just name your app with an ambiguous name and without an icon that describes what your app does, because your app will still be visible in your application manager from your phone settings. Along with that, you can do the following:

    To create an app that does not have an icon in the Home Launcher, just remove the intent filter android.intent.category.LAUNCHER of your activity from the AppManifest.xml.

    To implement your background application, it strongly depends on what you want to do. You can create a Service for long running tasks, BroadcastReceiver to react to specific events or activities with intent filters.

    Edit:

    In order to let your app work automatically, you must put your app in this folder /system/priv-app. This way, your app will be started everytime you boot your device.