Search code examples
androidlinuxlinux-kerneldaemonlinux-device-driver

Android c++ service at boot time


I need to start a service at boot time in android i don't use broadcast receiver , i wrote a service in c++ because i need access driver libusb layer to communicate with my extrernal device ,the service is working properly if i started manualy,if i want to start the service at boot time means i need to edit inir.rc file in android if i do that it also working good .but the problem is i cant edit the init.rc in all devices. i put my service in Sytem/bin location and edit the init.rc file as follow

service sampleservice/system/bin/sampleservice
              oneshot
              disable

for manualy i started the service from terminal like this

#./system/bin/sampleservice

but i cant start the service at each and every time when system restarts do have any idea to start the service at boot time with out edit init.rc


Solution

  • As far as I know (NDK reference, google groups like google-ndk, android-developers, etc.), there is no reliable way of starting a native binary as a service other than init.rc.

    For your particular use case, you might give USB SDK described here: http://developer.android.com/guide/topics/connectivity/usb/index.html a try. However if this is not sufficient or if you want to support OS API levels below 10, then I believe there is no simple way to achieve what you want.

    Providing that your service is not critical (i.e. the system does not depend on it), I've seen a couple of threads here and on the groups that advise to create a regular Android application which you would create using ADT. It would be minimal and contain:

    This method has also been recommended when installation of the service on non-rooted devices was necessary. However, I have never tried it. I know it's not much, but I wanted to share what I know on the subject.