Android - Kill another app without system permission

Maxime Godinas :

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.

I have tried to kill the background process (I know the package name of the app) but it doesn't work.

So, is there a way to kill other apps with my app, without haveing system permissions?

AlexPad :

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 :

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);    
        }

    }

}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324282&siteId=1