Example usage for android.content Context getPackageManager

List of usage examples for android.content Context getPackageManager

Introduction

In this page you can find the example usage for android.content Context getPackageManager.

Prototype

public abstract PackageManager getPackageManager();

Source Link

Document

Return PackageManager instance to find global package information.

Usage

From source file:Main.java

public static PackageInfo getPackageInfo(Context context) {
    try {//from  w  ww.j a  v a  2  s  .  c om
        return context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
    } catch (PackageManager.NameNotFoundException e) {
        // Should never happen.
        throw new RuntimeException(e);
    }
}

From source file:Main.java

public static boolean checkIsInstallHuaweiAccount(Context context) {
    PackageManager packMgr = context.getPackageManager();
    try {//  w w  w  . ja va 2 s. c  o m
        return (null != packMgr.getApplicationInfo("com.huawei.hwid", PackageManager.GET_META_DATA));
    } catch (NameNotFoundException e) {
        return false;
    }
}

From source file:Main.java

public static boolean appInstalledOrNot(String uri, Context context) {
    PackageManager pm = context.getPackageManager();
    boolean app_installed;
    try {/* w  w  w. ja v  a  2 s .  c o m*/
        pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
        app_installed = true;
    } catch (PackageManager.NameNotFoundException e) {
        app_installed = false;
    }
    return app_installed;
}

From source file:Main.java

private static int getVersionCode(Context context) {
    try {//from w  w  w .j  a  v a  2s  . com
        return context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionCode;
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    return -1;
}

From source file:Main.java

public static void openApp(Context context, String packageName) {
    Intent intent = context.getPackageManager().getLaunchIntentForPackage(packageName);
    context.startActivity(intent);//from  w  w w  .  j a v  a 2 s  .co  m
}

From source file:Main.java

/**
 * Test if this device is a Google TV./*  w ww  .  j  a va2 s  . co  m*/
 * 
 * See 32:00 in "Google I/O 2011: Building Android Apps for Google TV"
 * http://www.youtube.com/watch?v=CxLL-sR6XfM
 * 
 * @return true if google tv
 */
public static boolean isGoogleTV(Context context) {
    final PackageManager pm = context.getPackageManager();
    return pm.hasSystemFeature("com.google.android.tv");
}

From source file:Main.java

public static int getVersionCode(Context context) {
    try {//from  w w  w  .j ava 2  s  .  c  o m
        return context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionCode;
    } catch (Exception e) {
        Log.e(TAG, "Cannot find package and its version info.");
        return -1;
    }
}

From source file:Main.java

public static String getVersionName(Context context) {
    PackageManager pm = context.getPackageManager();
    try {//  w  w w.  j  a v  a2s  .  c  om
        PackageInfo packageInfo = pm.getPackageInfo(context.getPackageName(), 0);
        if (packageInfo != null) {
            return packageInfo.versionName;
        }
    } catch (PackageManager.NameNotFoundException e) {
    } catch (RuntimeException e) {
    }
    return null;
}

From source file:Main.java

public static PackageInfo getPackage(Context context) {
    try {/*from  w  w w.ja  va2 s .com*/
        return context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
    } catch (NameNotFoundException e) {
        // Should not happen
        return null;
    }
}

From source file:Main.java

public static int getVersionCode(Context context) {
    PackageManager pm = context.getPackageManager();
    PackageInfo pi;/*from  www . ja v  a2  s.com*/
    try {
        pi = pm.getPackageInfo(context.getPackageName(), 0);
        return pi.versionCode;
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    return 0;
}