How to get pid of android application without using adb shell?
As every application has its own process id, one can get it by
int pid = android.os.Process.myPid();
Android get PID of other applications
I think you'd need to use ActivityManager: see http://developer.android.com/reference/android/app/ActivityManager.RunningAppProcessInfo.html for the process info. You could:
- Get all running app processes.
- Find your app.
- Get its PID.
Android: determinine my app's process ID?
You're looking for this, I think:
int id = android.os.Process.myPid();
adb: Find PID from the adb shell
Not sure if you can get the PID directly however you can try the following
set `ps |grep android.process.acore`
echo $2
This has the affect of setting the output of the ps command into variables $1, $2, $3 etc. The PID value is in $2
How to get PID from package name?
try
restartPackage code
ActivityManager aM = (ActivityManager);
getApplicationContext().getSystemService(getApplicationContext().ACTIVITY_SERVICE);
aM.restartPackage("com.android.email");
Kill BackGround Process Code
ActivityManager aM = (ActivityManager)
getApplicationContext().getSystemService(Catalogue.content_holder.getApplicationContext().ACTIVITY_SERVICE);
aM.killBackgroundProcesses("com.android.email");
Here is code which fetches all running Application and check wether email app is already running or not , if it is running then kill that process
ActivityManager manager = (ActivityManager) getApplicationContext.getSystemService(getApplicationContext.ACTIVITY_SERVICE);
List<RunningAppProcessInfo> activityes = ((ActivityManager)manager).getRunningAppProcesses();
for (int iCnt = 0; iCnt < activityes.size(); iCnt++){
System.out.println("APP: "+iCnt +" "+ activityes.get(iCnt).processName);
if (activityes.get(iCnt).processName.contains("com.android.email")){
android.os.Process.sendSignal(activityes.get(iCnt).pid, android.os.Process.SIGNAL_KILL);
android.os.Process.killProcess(activityes.get(i).pid);
//manager.killBackgroundProcesses("com.android.email");
//manager.restartPackage("com.android.email");
System.out.println("Inside if");
}
}
Related Topics
Android - Set a Progressbar to Be a Vertical Bar Instead of Horizontal
How To: Install Plugin in Android Studio
Bitmapdrawable Deprecated Alternative
How to Fix Android Studio Getting Stuck Executing Gradle Tasks
Android: Why Does Long Click Also Trigger a Normal Click
Phone Number Validation Android
Error: Error Parsing Xml: Not Well-Formed (Invalid Token) ...
How to Deal with Deprecated Classes in Android to Keep Compatibility
How to Prevent The Activity from Loading Twice on Pressing The Button
Signing My Android Application as System App
How to Make Space Between Linearlayout Children
How to Install/Update/Remove APK Using "Packageinstaller" Class in Android L
How to Create Listview Inside Dialog
How to Implement Ssl Certificate Pinning While Using React Native