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

public static PackageInfo getPackageInfo(Context context) {
    PackageInfo packInfo = null;//from   www .  j  av  a  2  s  .co m
    try {
        PackageManager packageManager = context.getPackageManager();
        packInfo = packageManager.getPackageInfo(context.getPackageName(), PackageManager.GET_ACTIVITIES);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return packInfo;
}

From source file:Main.java

public static int getVersionCode(Context context) throws PackageManager.NameNotFoundException {
    PackageManager packageManager = context.getPackageManager();
    PackageInfo packageInfo = packageManager.getPackageInfo(context.getPackageName(),
            PackageManager.GET_ACTIVITIES);
    return packageInfo.versionCode;
}

From source file:Main.java

@SuppressWarnings("unused")
private static boolean isIntentAvailable(Context context, Intent intent) {
    PackageManager packageManager = context.getPackageManager();
    List<ResolveInfo> list = packageManager.queryIntentActivities(intent, PackageManager.GET_ACTIVITIES);
    return list.size() > 0;
}

From source file:Main.java

public static String getVersionName(Context context) throws PackageManager.NameNotFoundException {
    PackageManager packageManager = context.getPackageManager();
    PackageInfo packageInfo = packageManager.getPackageInfo(context.getPackageName(),
            PackageManager.GET_ACTIVITIES);
    return packageInfo.versionName;
}

From source file:Main.java

public static String getPackageByApkFilePath(Context context, String path) {
    PackageManager pm = context.getPackageManager();
    String packageName = "";
    PackageInfo info = pm.getPackageArchiveInfo(path, PackageManager.GET_ACTIVITIES);
    ApplicationInfo appInfo = null;/* w  w w  . ja va 2s  .  c  o  m*/
    if (info != null) {
        appInfo = info.applicationInfo;
        packageName = appInfo.packageName;
        //            System.out.println("packageName:" + packageName);
    }
    return packageName;
}

From source file:Main.java

private static boolean isIntentAvailable(Context context, Intent intent) {
    final PackageManager packageManager = context.getPackageManager();
    List<ResolveInfo> list = packageManager.queryIntentActivities(intent, PackageManager.GET_ACTIVITIES);
    return list.size() > 0;
}

From source file:Main.java

public static boolean isAppExists(Context context, String packageName) {
    PackageManager pm = context.getPackageManager();
    try {/*  w w  w.  j  a  v a2  s  . c om*/
        PackageInfo packageInfo = pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);
        if (packageInfo != null) {
            return true;
        }
    } catch (NameNotFoundException e) {
        return false;
    }

    return true;
}

From source file:Main.java

/**
 * Checks if app given by package name is installed on device.
 * //  w w w  . j av a2  s  . c  om
 * @param packageName
 *            The package name where the app should be found
 * @return true if app is installed on device. false if not.
 */
public static boolean isInstalled(String packageName, Context ctx) {
    PackageManager pm = ctx.getPackageManager();
    try {
        pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);
        return true;
    } catch (PackageManager.NameNotFoundException e) {
        return false;
    }
}

From source file:Main.java

public static boolean isIntentAvailable(Context context, Intent intent) {
    if (intent == null) {
        return false;
    }//from  ww w .ja v a2 s .c  o m
    final PackageManager packageManager = context.getPackageManager();
    List<ResolveInfo> list = packageManager.queryIntentActivities(intent, PackageManager.GET_ACTIVITIES);
    return list.size() > 0;
}

From source file:Main.java

public static void collectDeviceInfo(Context ctx, HashMap<String, String> infos) {
    try {/*ww  w  .j a v a2s .com*/
        PackageManager pm = ctx.getPackageManager();
        PackageInfo pi = pm.getPackageInfo(ctx.getPackageName(), PackageManager.GET_ACTIVITIES);
        if (pi != null) {
            String versionName = pi.versionName == null ? "null" : pi.versionName;
            String versionCode = pi.versionCode + "";
            infos.put("versionName", versionName);
            infos.put("versionCode", versionCode);
        }
    } catch (NameNotFoundException e) {
        e.getMessage();
    }
    Field[] fields = Build.class.getDeclaredFields();
    for (Field field : fields) {
        try {
            field.setAccessible(true);
            infos.put(field.getName(), field.get(null).toString());
        } catch (Exception e) {
            e.getMessage();
        }
    }
}