Я ненавижу, когда программисты говорят "это невозможно!" Я думаю, что "всегда есть выход"
public static void killAppByPermission (Context context, String permissionToKill)
{
try
{
PackageManager p = context.getPackageManager();
final List <PackageInfo> appinstall = p.getInstalledPackages(PackageManager.GET_PERMISSIONS);
for(PackageInfo pInfo:appinstall)
{
String[] reqPermission = pInfo.requestedPermissions;
if(reqPermission != null)
{
for(int i=0;i<reqPermission.length;i++)
{
if (((String)reqPermission[i]).toLowerCase().contains(permissionToKill.toLowerCase()))
{
killAppByPackName(pInfo.packageName.toString());
break;
}
}
}
}
}
catch (Throwable t){t.printStackTrace();}
}
public static void killAppByPackName (String packageToKill)
{
try
{
ActivityManager actvityManager = (ActivityManager) Sett.context.getSystemService(Context.ACTIVITY_SERVICE);
final List<RunningAppProcessInfo> procInfos = actvityManager.getRunningAppProcesses();
for (RunningAppProcessInfo runningAppProcessInfo : procInfos)
{
//Log.e("running",runningAppProcessInfo.processName);
if(runningAppProcessInfo.processName.toLowerCase().contains(packageToKill.toLowerCase()))
{
android.os.Process.sendSignal(runningAppProcessInfo.pid, android.os.Process.SIGNAL_KILL);
actvityManager.killBackgroundProcesses(packageToKill);
//Log.e("killed", "!!! killed "+ packageToKill);
}
}
}
catch (Throwable t){History.Error(t);}
}
public static void killAppByName (Context context, String appNameToKill)
{
try
{
ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningAppProcessInfo> listOfProcesses = manager.getRunningAppProcesses();
for (ActivityManager.RunningAppProcessInfo process : listOfProcesses)
{
if (process.processName.toLowerCase().contains(appNameToKill.toLowerCase()))
{
//Log.e("killed", process.processName);
manager.killBackgroundProcesses(process.processName);
break;
}
}
}
catch (Throwable t){t.printStackTrace();}
}