Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
417 views
in Technique[技术] by (71.8m points)

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...