如何在Android中停止其他应用的服务?

时间:2023-01-26 20:45:45

On my device runs a service in an app (its not my app and I cannot uninstall it and my device is not rooted) that is always draining power. I can stop that service in my devices application settings but is there a way to stop it programatically, so I don't have to do that manually all the time ?

在我的设备上运行应用程序中的服务(它不是我的应用程序,我无法卸载它,我的设备没有root),这总是耗电。我可以在我的设备应用程序设置中停止该服务,但有没有办法以编程方式停止它,所以我不必一直手动执行此操作?

Could maybe something like stopService(...); work ?

也许像stopService(...);工作?

Is there maybe a way to change the scheduler to prevent the restarts of the service ?

是否有可能更改调度程序以防止重新启动服务?

"W/ActivityManager(178): Scheduling restart of crashed service xxxx in 5000ms

2 个解决方案

#1


1  

Get the process id of that particular application and then

获取该特定应用程序的进程ID然后

android.os.Process.killProcess(processIdKillService)

#2


0  

Here is a long shot (I've never tried it):

这是一个远景(我从未尝试过):

  1. Create a Context instance for that app using Context.createPackageContext()
  2. 使用Context.createPackageContext()为该应用程序创建一个Context实例

  3. Use it to stop the service via Context.stopService()
  4. 使用它通过Context.stopService()停止服务

#1


1  

Get the process id of that particular application and then

获取该特定应用程序的进程ID然后

android.os.Process.killProcess(processIdKillService)

#2


0  

Here is a long shot (I've never tried it):

这是一个远景(我从未尝试过):

  1. Create a Context instance for that app using Context.createPackageContext()
  2. 使用Context.createPackageContext()为该应用程序创建一个Context实例

  3. Use it to stop the service via Context.stopService()
  4. 使用它通过Context.stopService()停止服务