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.
The package name of an Android app uniquely identifies your app on the device, in Google Play Store, and in supported third-party Android stores.
No, every app should have a unique package name. If you install an app with a package name which is already used in another installed app, then it will replace it. So there should be other reasons. One guess is queryIntentActivities retrieves all activities that can be performed for the given intent.
When an application component starts and the application does not have any other components running, the Android system starts a new Linux process for the application with a single thread of execution. By default, all components of the same application run in the same process and thread (called the "main" thread).
One method to look up an app's package name is to find the app in the Google Play app store using a web browser. The package name will be listed at the end of the URL after the '? id='. In the example below, the package name is 'com.google.android.gm'.
By default android takes the package name as the process name. But if you define process property in application tag in manifest file android:process="com.example.newprocessname"
then the application will run with this name "com.example.newprocessname".
As for your questions,
1-> In this case your application name is same as the default package name, that's why it is working. Try changing the process name. It'll not work.
2-> That's true. It is by default. Refer to "android:process" in the following link: https://developer.android.com/guide/topics/manifest/application-element.html
Hope this answers your question!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With