简体   繁体   English

Android - 在没有系统权限的情况下杀死另一个应用程序

[英]Android - Kill another app without system permission

I have an app that can start other apps.我有一个可以启动其他应用程序的应用程序。

This works, I can do that.这行得通,我可以做到。

Now, I would like to also kill the apps started by my app.现在,我还想杀死由我的应用程序启动的应用程序。

But I can't find a way to do that (My app doesn't have system permissions).但我找不到这样做的方法(我的应用程序没有系统权限)。

I have tried to list all currently running processes in order to get their PID and to kill with it, but I can only get the PID of my app.我试图列出所有当前正在运行的进程以获取它们的 PID 并用它杀死,但我只能获取我的应用程序的 PID。

I have tried to kill the background process (I know the package name of the app) but it doesn't work.我试图杀死后台进程(我知道应用程序的 package 名称)但它不起作用。

So, is there a way to kill other apps with my app, without haveing system permissions?那么,有没有办法在没有系统权限的情况下用我的应用程序杀死其他应用程序?

I think that first of all to do this you should seriously read the Google guidelines to make sure you have to publish it.我认为首先要做到这一点,你应该认真阅读谷歌指南,以确保你必须发布它。 It is essential to ask permission for everything from the end user.必须向最终用户征求所有内容的许可。 Ultimately, you can see if I'm not mistaken which other packages are in runtime, once you know it you might find a way to kill them.最终,您可以查看我是否没有弄错哪些其他软件包在运行时,一旦您知道了,您可能会找到杀死它们的方法。 Try this and add "android.permission.KILL_BACKGROUND_PROCESSES" permission on your Manifest:试试这个并在你的清单上添加“android.permission.KILL_BACKGROUND_PROCESSES”权限:

private void killOtherApps(String packageTokill){

    List<ApplicationInfo> packages;
    PackageManager pm;
    pm = getPackageManager();
    //get a list of installed apps.
    packages = pm.getInstalledApplications(0);


    ActivityManager mActivityManager = (ActivityManager) MainActivity.this.getSystemService(Context.ACTIVITY_SERVICE);
    String myPackage = getApplicationContext().getPackageName();

    for (ApplicationInfo packageInfo : packages) {

        if((packageInfo.flags & ApplicationInfo.FLAG_SYSTEM)==1) {
            continue;
        }
        if(packageInfo.packageName.equals(myPackage)) {
            continue;
        }
        if(packageInfo.packageName.equals(packageTokill)) {
            mActivityManager.killBackgroundProcesses(packageInfo.packageName);    
        }

    }

}

It would be a huge security problem if what you want to do was permitted - so it's not.如果您想要做的事情被允许,那将是一个巨大的安全问题——所以事实并非如此。 There is no way around this - because that would be a huge security problem.没有办法解决这个问题——因为那将是一个巨大的安全问题。

You will require:您将需要:

<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" />
<uses-permission android:name="android.permission.GET_TASKS" />

Without those permissions, it is not possible.没有这些权限,这是不可能的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM