How to start and stop android service from a adb shell?

前端 未结 11 1033
别跟我提以往
别跟我提以往 2020-12-07 16:32

I need to write a shell script to start and stop an android service .

11条回答
  •  既然无缘
    2020-12-07 17:08

    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"

    
    
        
            
            
            
        
    
    

提交回复
热议问题