get Name From Package Name - Android App

Android examples for App:Package

Description

get Name From Package Name

Demo Code


//package com.java2s;
import android.content.Context;
import android.content.pm.ApplicationInfo;

import android.content.pm.PackageManager;

public class Main {
    public static String getNameFromPackageName(String packageName,
            Context context) {/* w  ww .  ja  va  2s.  c  o m*/
        PackageManager packageManager = context.getPackageManager();
        ApplicationInfo applicationInfo = null;
        try {
            applicationInfo = packageManager.getApplicationInfo(
                    packageName, 0);
        } catch (final PackageManager.NameNotFoundException e) {
        }
        if (applicationInfo != null) {
            return packageManager.getApplicationLabel(applicationInfo)
                    .toString();
        } else {
            return packageName;
        }

    }
}

Related Tutorials