Close another app from your app?
It is not possible to close the another app from your app.
It is ethically not correct and there is no official Android API as well.
Kill another application on Android?
You can only kill a process that has the same userID as the one that is doing the killing. If you are trying to kill your own process it should work. Otherwise you can't do it (unless you have a rooted device and your application has root priviledges).
Close(kill) another app in my application by package name
If you want to kill a background app , check the following code
public void amKillProcess(string package_name)
{
ActivityManager am = (ActivityManager)this.GetSystemService(Context.ActivityService);
var runningProcesses = am.RunningAppProcesses;
foreach (RunningAppProcessInfo runningProcess in runningProcesses)
{
if (runningProcess.ProcessName.Contains(package_name))
{
Android.OS.Process.KillProcess(runningProcess.Uid);
}
}
}
And if you want to kill a foreground app, you could use Adb
public class SuUtil
{
private static Java.Lang.Process process;
public static void kill(string packageName)
{
initProcess();
killProcess(packageName);
close();
}
private static void initProcess()
{
if (process == null)
try
{
process = Runtime.GetRuntime().Exec("su");
}
catch (IOException e)
{
}
}
private static void killProcess(string packageName)
{
System.IO.Stream output = process.OutputStream;
Java.Lang.String cmd = new Java.Lang.String("am force-stop " + packageName + " \n");
try
{
output.Write(cmd.GetBytes());
output.Flush();
}
catch (IOException e)
{
}
}
private static void close()
{
if (process != null)
try
{
process.OutputStream.Close();
process = null;
}
catch (IOException e)
{
}
}
}
Related Topics
Emulator Error: This Avd's Configuration Is Missing a Kernel File
Restrict API Requests to Only My Own Mobile App
How to Change the Spinner Background in Android
Get JSONarray Without Array Name
Checking Toast Message in Android Espresso
How to Get the Screensize Programmatically in Android
How to Put Gridview Inside Scrollview
Have Both Gms and Hms in the Project
Google Play Game Services - Unable to Sign In
Wifi Connect-Disconnect Listener
How to Make an Imageview in Circular Shape
Android Usb Host and Hidden Devices
How to Change the Textcolor on an Android Searchview
Get the Uri of an Image Stored in Drawable
How to Find If a Particular Package Exists on My Android Device