Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PackageManager's applicationInfo.name is always null

PackageManager pm = this.getPackageManager();
ActivityManager am = (ActivityManager) this.getSystemService(Context.ACTIVITY_SERVICE);

List<RunningAppProcessInfo> runningAppProcesses = am.getRunningAppProcesses();

for(RunningAppProcessInfo process : runningAppProcesses) {
    try {
        ApplicationInfo ai = pm.getApplicationInfo(process.processName, PackageManager.GET_META_DATA);
        Log.d(TAG, applicationInfo.name + "");
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }
}

process.processName returns a valid package name but applicationInfo.name is always null.

like image 428
Ragunath Jawahar Avatar asked Oct 26 '10 08:10

Ragunath Jawahar


2 Answers

Used applicationInfo.loadLabel(packageManagerInstance) to find the Application name, but there should be a reason why applicationInfo.name didn't work.

Edit

applicationInfo.name is the name of a Application subclass if you have any.

like image 99
Ragunath Jawahar Avatar answered Nov 15 '22 22:11

Ragunath Jawahar


The reason name is null is that it really is... null.

Please refer to the Android manifest documentation:

android:name The fully qualified name of an Application subclass implemented for the application. When the application process is started, this class is instantiated before any of the application's components.

The subclass is optional; most applications won't need one. In the absence of a subclass, Android uses an instance of the base Application class.

What you want is the name of the application, which is set in the label attribute of the application tag, and which Ragunath explained how to get.

like image 22
Daniel Szmulewicz Avatar answered Nov 16 '22 00:11

Daniel Szmulewicz