2

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

Mr.Cool
  • 1,525
  • 10
  • 32
  • 51

2 Answers2

1

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.

andr
  • 15,970
  • 10
  • 45
  • 59
  • thanks for your comment ,and one more thing can i start the native service from broadcast receiver? – Mr.Cool Feb 12 '13 at 11:32
  • basically - yes. you could use `Runtime.exec()` and run the whole process. *alternatively* you could create a bootstrapping function in the library, which would probably start a separate working thread. then you'd create a JNI method which would call the native bootstrapping function and simply call the JNI method from the receiver. – andr Feb 12 '13 at 11:37
  • i have one doubt , i start my service using broadcast receiver so it starts at boot but i cant access my external devices,if i start my service in terminal like ./system/bin/myservice it's working properly may be this because of permission issue? – Mr.Cool Feb 13 '13 at 11:35
  • this may be caused by permissions... *how exactly* do you start the service? what exactly are you experiencing? do you observe any exceptions? – andr Feb 14 '13 at 03:19
-1

I guess you need to make sure that the fs is up before you start the service.... A good idea, if you can compile from source, would be to enable Info logs in init code itself.

BR Subbu

Subbu
  • 61
  • 2