如何以编程方式停止(强制停止)其他应用程序Android? [英] How to stop (Force-Stop) other app programmatically Android?

查看:107
本文介绍了如何以编程方式停止(强制停止)其他应用程序Android?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图以编程方式停止其他应用程序,但我看到了很多示例,但是没有用.

I'm trying to stop others applications programmatically and i saw many samples, but didn't work.

try {
    ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);

    Process.killProcess(p.pid);
    Process.sendSignal(p.pid, Process.SIGNAL_KILL);
    manager.killBackgroundProcesses(p.getPackageName());
} catch (Exception e) {
    e.printStackTrace();
}

它没有用,但是我看到了通过adb完成它的另一种方法.

It didn't work, but i saw other way to do it over adb and it work.

adb shell am force-stop packagename

有人可以告诉我是否可以强制停止应用程序吗?

Could anyone tell me if is it possible to force-stop an application ?

推荐答案

如果设备已植根或应用程序已使用系统签名签名,则有可能.否则,运行此代码时会出现权限错误.

If device rooted or application signed with system signature, its possible. Otherwise you will get an permission error when run this code.

Process process = Runtime.getRuntime().exec("am force-stop packagename");

这篇关于如何以编程方式停止(强制停止)其他应用程序Android?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆