app Name Lookup - Android App

Android examples for App:App Information

Description

app Name Lookup

Demo Code


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

import android.util.Log;

public class Main {
    public static String appNameLookup(Context context, String packageName) {

        try {//from   w w  w  .ja va 2s . c o  m

            PackageManager pm = context.getPackageManager();
            ApplicationInfo ai = pm.getApplicationInfo(packageName, 0);

            return pm.getApplicationLabel(ai).toString();

        } catch (final PackageManager.NameNotFoundException e) {

            e.printStackTrace();
            Log.e("AppsHelper", "Could not resolve name " + packageName);

            return null;

        }

    }
}

Related Tutorials