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 boolean checkCameraHardWare(Context context) {
    PackageManager packageManager = context.getPackageManager();
    if (packageManager.hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
        return true;
    }//from w ww  .ja  v a2  s .  c  o m
    return false;
}

From source file:Main.java

public static int getPackageVersionNum(Context context) {
    PackageManager pm = context.getPackageManager();
    PackageInfo pi = null;/*from   w w w . j a v  a2  s  .  c o  m*/
    int versionNum = 0;
    try {
        pi = pm.getPackageInfo(context.getPackageName(), 0);
        versionNum = pi.versionCode;
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }
    return versionNum;
}

From source file:Main.java

public static boolean isAppInstalled(String uri, Context context) {
    PackageManager pm = context.getPackageManager();
    boolean app_installed;

    try {/*  w  w  w. j a  v  a2s .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

public static int getVersionCode(Context context) {
    PackageManager manager = context.getPackageManager();
    try {/*from  ww w.j  a  v a  2  s .c om*/
        PackageInfo info = manager.getPackageInfo(context.getPackageName(), 0);
        return info.versionCode;
    } catch (NameNotFoundException e) {
        e.printStackTrace();
        return 0;
    }
}

From source file:Main.java

public static String getVersionName(Context context) {
    PackageManager manager = context.getPackageManager();
    try {/*from  www . j a v  a  2  s  .  c o  m*/
        PackageInfo info = manager.getPackageInfo(context.getPackageName(), 0);
        return info.versionName;
    } catch (NameNotFoundException e) {
        e.printStackTrace();
        return null;
    }
}

From source file:Main.java

public static boolean isAppInstalled(Context context, String name) {
    try {/*from ww w .java  2  s  .  c om*/
        context.getPackageManager().getPackageInfo(name, 0);
        return true;
    } catch (Exception e) {
        return false;
    }
}

From source file:Main.java

public static PackageInfo getMyApkInfo(Context context) {
    PackageManager pm = context.getPackageManager();
    PackageInfo apkInfo = null;/*from  w w w . java 2s  . c  om*/
    try {
        apkInfo = pm.getPackageInfo(context.getPackageName(), 0);
    } catch (NameNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return apkInfo;
}

From source file:Main.java

public static String getVersionName(Context context) {
    PackageManager manager = context.getPackageManager();
    PackageInfo pInfo = new PackageInfo();
    try {/*from w w  w.j  av a2 s.com*/
        pInfo = manager.getPackageInfo(context.getPackageName(), 0);
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    return pInfo.versionName == null ? null : pInfo.versionName;
}

From source file:Main.java

public static void startApplication(Context mContext, String pkgName) {
    Intent launchIntent = mContext.getPackageManager().getLaunchIntentForPackage(pkgName);
    mContext.startActivity(launchIntent);
}

From source file:Main.java

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