I need to write a shell script to start and stop an android service .
To stop a service, you have to find service name using:
adb shell dumpsys activity services
for example: adb shell dumpsys activity services com.xyz.something
This will list services running for your package.
Output should be similar to:
ServiceRecord{xxxxx u0 com.xyz.something.beta/xyz.something.abc.XYZService}
Now select your service and run:
adb shell am stopservice
For example:
adb shell am stopservice com.xyz.something.beta/xyz.something.abc.XYZService
similarly, to start service:
adb shell am startservice
To access service, your service(in AndroidManifest.xml) should set exported="true"