By process I mean what we provide in android:process
and by package I mean package in
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.osg.appkiller"
android:versionCode="1"
android:versionName="1.0" >
More details Processes and Threads - Android Developer
I wanted to get application names of all running apps. So this is what I did after looking at various sources (and it works).
ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
PackageManager packageManager = getPackageManager();
final List<RunningAppProcessInfo> runningProcesses = activityManager.getRunningAppProcesses();
for(RunningAppProcessInfo processInfo : runningProcesses) {
CharSequence appName = null;
try {
appName = packageManager.getApplicationLabel(packageManager.getApplicationInfo(processInfo.processName, PackageManager.GET_META_DATA));
} catch (NameNotFoundException e) {
Log.e(TAG,"Application info not found for process : " + processInfo.processName,e);
}
}
If you see Documentation for PackageManager.getApplicationInfo
ApplicationInfo android.content.pm.PackageManager.getApplicationInfo(String packageName, int flags) throws NameNotFoundException
but I am passing
processInfo.processName
where processName is name of process running. So we are basically using process name as package name to get application info.
- First of all is this approach correct ?
- Secondly is it true that if we do not provide process for activities/services etc new process is created with same name as that of package name ?