Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is process name same as package name in android?

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.

  1. First of all is this approach correct ?
  2. 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 ?
like image 287
Aniket Thakur Avatar asked Dec 19 '14 18:12

Aniket Thakur


People also ask

What is package name in Android app?

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.

Can 2 apps have same package name?

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.

What is a process in Android?

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).

How do I find my Android package name?

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'.


1 Answers

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!

like image 110
Shirish Singh Avatar answered Sep 30 '22 08:09

Shirish Singh