I need to write a shell script to start and stop an android service .
Install ADB on Ubuntu For installing Android Debug Bridge (adb) command on Ubuntu, type below command on terminal $ sudo apt-get install adb Above command will also install android-libadb android-libbase android-libcutils android-liblog $ which adb /usr/bin/adb You can now check the adb version using command as below, ...
You can shut down Android using the ADB command (adb shell reboot -p) on your PC, but you need to enable USB debugging on Android and install ADB drivers on your PC.
To stop the adb server, use the adb kill-server command. You can then restart the server by issuing any other adb command.
To exit adb and return to the system shell use the $q or $Q command. To stop the debugger press <Ctrl>D. NOTE: adb cannot be stopped by pressing the Quit or Interrupt key.
I'm a beginner in Android, but got it working like this:
in AndroidManifest.xml, make sure you, inside <application>
, have something like this:
<service android:name="com.some.package.name.YourServiceSubClassName" android:permission="com.some.package.name.YourServiceSubClassName"> <intent-filter> <action android:name="com.some.package.name.YourServiceSubClassName"/> </intent-filter> </service>
where YourServiceSubClassName
extend android.app.Service
is your java class that is the service. Where com.some.package
is the package name, for me both in AndroidManifest.xml and in Java. Used a javabeat.net article as help, look for <service>
Note also, supposedly between the package name and the class name there should be .service.
in the text, I guess this is some convention, but for me this caused ClassNotFoundException
that I'm yet to solve.
Then, install your apk. I did from eclipse but also adb install -r yourApkHere.apk
should work. Uninstall is adb uninstall com.some.package.name
, btw.
You can start it from host system like this, thanks Just a Tim and MrRoy:
adb shell am startservice com.some.package.name/.YourServiceSubClassName
interestingly, I didn't need -n
.
To stop, I use
adb shell am force-stop com.some.package.name
Hope it helps.
As I'm a beginner, please feel freet to edit/comment to fix any misconceptions (eg. probably regarding .service.
in the component (?) name).
Starting a service:
adb shell am startservice ...
start a Service. Options are: --user | current: Specify which user to run as; if not specified then run as the current user.
Stopping a service:
adb shell am stopservice ...
stop a Service. Options are: --user | current: Specify which user to run as; if not specified then run as the current user.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With