Example usage for android.content.pm PackageManager GET_ACTIVITIES

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

Introduction

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

Prototype

int GET_ACTIVITIES

To view the source code for android.content.pm PackageManager GET_ACTIVITIES.

Click Source Link

Document

PackageInfo flag: return information about activities in the package in PackageInfo#activities .

Usage

From source file:Main.java

/**
 * Check if a certain application is installed on a device.
 *
 * @param context the applications context.
 * @param packageName the package name that you want to check.
 *
 * @return true if the application is installed, false otherwise.
 *//*  www  .j av a2  s.c  om*/
public static boolean isApplicationInstalled(Context context, String packageName) {
    PackageManager pm = context.getPackageManager();
    try {
        // Check if the package name exists, if exception is thrown, package name does not exist.
        pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);
        return true;
    } catch (PackageManager.NameNotFoundException e) {
        return false;
    }
}

From source file:Main.java

/**
 * check if assign package is installed in system
 * *///from  w ww .  j  av a  2s . c o  m
public static boolean isPackageInstalled(String packagename, Context context) {
    PackageManager pm = context.getPackageManager();
    try {
        pm.getPackageInfo(packagename, PackageManager.GET_ACTIVITIES);
        return true;
    } catch (NameNotFoundException e) {
        return false;
    }
}

From source file:Main.java

public static PackageInfo getPackageInfo(Context context, String apkFilepath) {
    return getPackageInfo(context, apkFilepath, PackageManager.GET_ACTIVITIES | PackageManager.GET_SERVICES);
}

From source file:Main.java

public static Bitmap getApkIcon(Context context, String apkPath) {
    Bitmap thumb = null;/*from ww w. j a  v a 2 s . com*/
    PackageManager pm = context.getPackageManager();
    PackageInfo info = pm.getPackageArchiveInfo(apkPath, PackageManager.GET_ACTIVITIES);
    if (info != null) {
        ApplicationInfo appInfo = info.applicationInfo;
        appInfo.sourceDir = apkPath;
        appInfo.publicSourceDir = apkPath;
        try {
            thumb = ((BitmapDrawable) appInfo.loadIcon(pm)).getBitmap();
        } catch (OutOfMemoryError e) {

        }
    }
    return thumb;
}

From source file:Main.java

private static boolean isV4AInstalled(Context context) {
    PackageManager pm = context.getPackageManager();
    try {//from   w ww .  j  a v a  2 s .c  o m
        pm.getPackageInfo("com.vipercn.viper4android_v2", PackageManager.GET_ACTIVITIES);
        return true;
    } catch (NameNotFoundException e) {
        return false;
    }
}

From source file:Main.java

public static boolean isGooglePlayInstalled(Context context) {
    PackageManager pm = context.getPackageManager();
    boolean app_installed;
    try {//from  w w  w. j a va  2s.co  m
        PackageInfo info = pm.getPackageInfo("com.android.vending", PackageManager.GET_ACTIVITIES);
        String label = (String) info.applicationInfo.loadLabel(pm);
        app_installed = (label != null && label.equals("Google Play Store"));
    } catch (PackageManager.NameNotFoundException e) {
        app_installed = false;
    }
    return app_installed;
}

From source file:Main.java

public static Drawable getApkIcon(Context context, String apkPath) {
    PackageManager pm = context.getPackageManager();
    PackageInfo info = pm.getPackageArchiveInfo(apkPath, PackageManager.GET_ACTIVITIES);
    if (info != null) {
        info.applicationInfo.sourceDir = apkPath;
        info.applicationInfo.publicSourceDir = apkPath;
        ApplicationInfo applicationInfo = info.applicationInfo;
        return applicationInfo.loadIcon(pm);
    }//  ww w .ja  v a2s . com
    return null;
}

From source file:Main.java

public static PackageInfo getPackageInfo(Context context, String apkFilepath) {
    PackageManager pm = context.getPackageManager();
    PackageInfo pkgInfo = null;//from  w  w  w . j  av  a 2 s  .  c o m
    try {
        pkgInfo = pm.getPackageArchiveInfo(apkFilepath, PackageManager.GET_ACTIVITIES);
    } catch (Exception e) {
        // should be something wrong with parse
        e.printStackTrace();
    }

    return pkgInfo;
}

From source file:Main.java

/**
 * Judge whether an app is dubuggable by package name
 *
 * @param context/* ww w  .j  a va2  s .co  m*/
 * @param packageName
 * @return
 */
public static boolean isApkDebugable(Context context, String packageName) {
    try {
        PackageInfo pkginfo = context.getPackageManager().getPackageInfo(packageName,
                PackageManager.GET_ACTIVITIES);
        if (pkginfo != null) {
            ApplicationInfo info = pkginfo.applicationInfo;
            return (info.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
        }
    } catch (Exception e) {
    }
    return false;
}

From source file:Main.java

/**
 * Check if BerryMotes app is installed 
 * // w w  w .  ja v  a  2 s.  c  o  m
 * @param context Android context
 * @param version BerryMotes version
 * @return true if BerryMotes is installed
 */
public static boolean isBerryMotesInstalled(Context context, int version) {
    PackageManager pm = context.getPackageManager();
    try {
        PackageInfo pi = pm.getPackageInfo(BERRYMOTES_NAME, PackageManager.GET_ACTIVITIES);
        return pi.versionCode >= version;
    } catch (PackageManager.NameNotFoundException e) {
        return false;
    }
}