Example usage for android.content.pm PackageManager getApplicationInfo

List of usage examples for android.content.pm PackageManager getApplicationInfo

Introduction

In this page you can find the example usage for android.content.pm PackageManager getApplicationInfo.

Prototype

public abstract ApplicationInfo getApplicationInfo(String packageName, @ApplicationInfoFlags int flags)
        throws NameNotFoundException;

Source Link

Document

Retrieve all of the information we know about a particular package/application.

Usage

From source file:Main.java

public static String getApplicationName(Activity context) {
    PackageManager packageManager = null;
    ApplicationInfo applicationInfo = null;
    try {//  w  ww .  ja v  a2  s .  c o m
        packageManager = context.getPackageManager();
        applicationInfo = packageManager.getApplicationInfo(context.getPackageName(), 0);
    } catch (PackageManager.NameNotFoundException e) {
        applicationInfo = null;
    }
    return (String) packageManager.getApplicationLabel(applicationInfo);
}

From source file:Main.java

public static boolean isDebuggable(Context context) {
    PackageManager pacMan = context.getPackageManager();
    String pacName = context.getPackageName();
    ApplicationInfo appInfo = null;/*ww  w .  j av  a  2 s . co  m*/
    try {
        appInfo = pacMan.getApplicationInfo(pacName, 0);
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }

    if (appInfo != null) {
        if ((appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
            return true;
        } else {
            return false;
        }
    } else {
        return false;
    }

}

From source file:Main.java

public static String getApplicationName(Context context) {
    PackageManager packageManager = null;
    ApplicationInfo applicationInfo = null;
    try {//ww  w.  j a  v a2s .  c  o  m
        packageManager = context.getPackageManager();
        applicationInfo = packageManager.getApplicationInfo(context.getPackageName(), 0);
    } catch (PackageManager.NameNotFoundException e) {
        applicationInfo = null;
    }
    String applicationName = (String) packageManager.getApplicationLabel(applicationInfo);
    return applicationName;
}

From source file:Main.java

/**
 * check if installed/* w ww .  ja v a2 s .c  o m*/
 * @param context
 * @param packageName
 * @return
 */
public static boolean isAppInstalled(Context context, String packageName) {

    if (TextUtils.isEmpty(packageName)) {
        return false;
    }

    PackageManager packageManager = context.getPackageManager();
    ApplicationInfo applicationInfo = null;

    try {
        applicationInfo = packageManager.getApplicationInfo(packageName, 0);
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    return applicationInfo != null;
}

From source file:Main.java

public static Bitmap packageNameToBitmap(Context context, PackageManager packageManager, String packageName,
        int resId) {
    try {/*  w  ww .  j a  v  a  2 s  .  c  om*/
        ApplicationInfo applicationInfo = packageManager.getApplicationInfo(packageName,
                PackageManager.GET_META_DATA);
        Resources resources = packageManager.getResourcesForApplication(applicationInfo);
        Bitmap bitmap = resIdToBitmap(resources, resId);
        if (bitmap == null) {
            Drawable drawable = packageManager.getApplicationIcon(packageName);
            if (drawable != null) {
                bitmap = drawableToBitmap(drawable);
            }
        }
        return bitmap;
    } catch (PackageManager.NameNotFoundException | Resources.NotFoundException e) {
        e.printStackTrace();
        return null;
    }
}

From source file:org.microg.gms.auth.AuthManagerServiceImpl.java

private static CharSequence getPackageLabel(String packageName, PackageManager pm) {
    try {/*  ww  w. j  av a 2  s .  c o  m*/
        return pm.getApplicationLabel(pm.getApplicationInfo(packageName, 0));
    } catch (PackageManager.NameNotFoundException e) {
        return packageName;
    }
}

From source file:Main.java

public static ApplicationInfo findMetaData(Context ctx, String key) {
    PackageManager pm = ctx.getPackageManager();
    try {/*from  w w w . j  a va  2 s .  c  om*/
        List<PackageInfo> pkgList = pm.getInstalledPackages(0);
        for (PackageInfo info : pkgList) {
            ApplicationInfo appInfo = pm.getApplicationInfo(info.packageName, PackageManager.GET_META_DATA);
            Bundle bd = appInfo.metaData;
            if (bd == null)
                continue;
            Object obj = bd.get(key);
            if (obj != null) {
                //                    System.out.println("find it , panme : "+appInfo.packageName);
                return appInfo;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

public static String getAppName(Context context, Intent appIntent) {

    if (appIntent.hasExtra(Intent.EXTRA_SHORTCUT_NAME)) {
        return appIntent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
    }/*from  w ww  .jav  a 2s.  co  m*/

    if (appIntent.hasExtra(Intent.EXTRA_SHORTCUT_INTENT)) {
        appIntent = appIntent.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
    }
    ComponentName componentName = appIntent.getComponent();

    PackageManager pm = context.getPackageManager();

    ApplicationInfo appInfo = null;
    ActivityInfo activityInfo = null;
    try {
        appInfo = pm.getApplicationInfo(componentName.getPackageName(), 0);
    } catch (PackageManager.NameNotFoundException e) {
        appInfo = null;
    }
    try {
        activityInfo = pm.getActivityInfo(componentName, 0);
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    if (appInfo == null) {
        return null;
    } else {
        CharSequence appName = pm.getApplicationLabel(appInfo);
        CharSequence activityName = null;

        if (activityInfo != null) {
            activityName = activityInfo.loadLabel(pm);
        }

        if (activityName != null) {
            return activityName.toString();
        }

        if (appName != null) {
            appName.toString();
        }

        return null;
    }
}

From source file:io.lqd.sdk.gcm.LQMessageHandler.java

private static String getAppName(Context context) {
    PackageManager manager = context.getPackageManager();
    try {//from w w w.  j a  v  a 2 s  .c  om
        ApplicationInfo appinfo = manager.getApplicationInfo(context.getPackageName(), 0);
        return manager.getApplicationLabel(appinfo).toString();
    } catch (PackageManager.NameNotFoundException e) {
        return "";
    }
}

From source file:Main.java

@TargetApi(16)
static void setAndroidBeam(Activity activity, String packageName) {
    if (Build.VERSION.SDK_INT < 16)
        return;//w ww. ja v a 2s. c o m
    PackageManager pm = activity.getPackageManager();
    NfcAdapter nfcAdapter = getAdapter(activity);
    if (nfcAdapter != null) {
        ApplicationInfo appInfo;
        try {
            appInfo = pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA);
            Uri uris[] = { Uri.parse("file://" + appInfo.publicSourceDir), };
            nfcAdapter.setBeamPushUris(uris, activity);
        } catch (NameNotFoundException e) {
            e.printStackTrace();
        }
    }
}