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

/**
 * Convenience method to test whether the Collector application is installed on the device or not
 *
 * @param context an application context
 * @return true if Collector is installed on the device, false otherwise
 *///  w  w w  . j a v  a  2s . c o m
public static boolean isCollectorInstalled(Context context) {
    PackageManager pm = context.getPackageManager();
    try {
        pm.getPackageInfo(COLLECTOR_URI, PackageManager.GET_ACTIVITIES);
        return true;
    } catch (PackageManager.NameNotFoundException ignore) {
    }

    return false;
}

From source file:Main.java

@Nullable
public static Bitmap extractApkIcon(@NonNull final PackageManager pm, @NonNull final File file) {
    final String filePath = file.getPath();
    final PackageInfo packageInfo = pm.getPackageArchiveInfo(filePath, PackageManager.GET_ACTIVITIES);
    if (packageInfo != null) {
        final ApplicationInfo appInfo = packageInfo.applicationInfo;
        if (appInfo != null) {
            appInfo.sourceDir = filePath;
            appInfo.publicSourceDir = filePath;
            final Drawable icon = appInfo.loadIcon(pm);
            if (icon != null) {
                return ((BitmapDrawable) icon).getBitmap();
            }/*from   w  w  w .j a va 2  s  .c  o m*/
        }
    }
    return null;
}

From source file:Main.java

public static PackageInfo getPackageInfo(Context context) {
    PackageInfo info = null;//from  w w w.  ja va2s.  co  m
    try {
        String packageName = context.getPackageName();
        info = context.getPackageManager().getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return info;
}

From source file:Main.java

/**
 * Get the package info of the specified apk file.
 * //  ww  w .  ja  v  a 2  s.c o m
 * @param  context the context
 * @param  apkFile the apk file
 * @return
 */
public static PackageInfo getApkInfo(Context context, File apkFile) {
    if (context == null || apkFile == null || !apkFile.exists()) {
        return null;
    }

    PackageManager packageManager = context.getPackageManager();
    PackageInfo pkgInfo = packageManager.getPackageArchiveInfo(apkFile.getAbsolutePath(),
            PackageManager.GET_ACTIVITIES);

    return pkgInfo;
}

From source file:Main.java

public static PackageInfo getPackageInfo(Context context, String apkFilePath) {
    PackageManager pm = context.getPackageManager();
    PackageInfo packageInfo = null;/*from  www . j  a va 2  s.c o m*/
    try {
        packageInfo = pm.getPackageArchiveInfo(apkFilePath,
                PackageManager.GET_ACTIVITIES | PackageManager.GET_SERVICES);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return packageInfo;
}

From source file:Main.java

/**
 * Checks if an app with the specified package name is installed
 *
 * @param context//w w  w. j av a  2s .c  o m
 * @param packageName The package name of the app to check
 * @return <b>true</b> if the app exists and successfully launched, <b>false</b> otherwise
 */
public static boolean isInstalled(Context context, String packageName) {
    final PackageManager packageManager = context.getPackageManager();
    try {
        packageManager.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);
        return true;
    } catch (PackageManager.NameNotFoundException e) {
        return false;
    }
}

From source file:Main.java

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

    return pkgInfo;
}

From source file:com.cw.litenote.util.EULA_dlg.java

private PackageInfo getPackageInfo() {
    PackageInfo info = null;/*from   ww w  . j  a  va 2 s .  c om*/
    try {
        info = mAct.getPackageManager().getPackageInfo(mAct.getPackageName(), PackageManager.GET_ACTIVITIES);
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    return info;
}

From source file:Main.java

public static boolean isInstalled(Context ctx, String packageName) {
    SharedPreferences sp = ctx.getSharedPreferences(DIGG_PREFERENCES, Context.MODE_PRIVATE);
    if (sp.contains(packageName)) {
        return true;
    } else {//from w w w  . j  a  v a 2  s  .  c  om
        PackageManager pm = ctx.getPackageManager();
        try {
            pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);
            sp.edit().putInt(packageName, 1).commit();
            return true;
        } catch (Exception e) {
            return false;
        }
    }
}

From source file:simonlang.coastdove.core.ui.add_app.AppListLoader.java

@Override
public ArrayList<ApplicationInfo> loadInBackground() {
    final PackageManager packageManager = getContext().getPackageManager();
    List<PackageInfo> packageInfos = packageManager.getInstalledPackages(PackageManager.GET_ACTIVITIES);

    ArrayList<ApplicationInfo> data = new ArrayList<>();
    for (int i = 0; i < packageInfos.size(); ++i) {
        PackageInfo packageInfo = packageInfos.get(i);
        data.add(packageInfo.applicationInfo);
    }//  www . j ava  2  s  . c o  m

    Collections.sort(data, new Comparator<ApplicationInfo>() {
        @Override
        public int compare(ApplicationInfo lhs, ApplicationInfo rhs) {
            String lhsAppName = lhs.loadLabel(packageManager).toString();
            String rhsAppName = rhs.loadLabel(packageManager).toString();
            return lhsAppName.compareTo(rhsAppName);
        }
    });

    return data;
}