Example usage for android.content.pm PackageManager getPackageInfo

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

Introduction

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

Prototype

public abstract PackageInfo getPackageInfo(VersionedPackage versionedPackage, @PackageInfoFlags int flags)
        throws NameNotFoundException;

Source Link

Document

Retrieve overall information about an application package that is installed on the system.

Usage

From source file:org.wso2.emm.agent.utils.CommonUtils.java

public static boolean isSystemAppInstalled(Context context) {
    PackageManager packageManager = context.getPackageManager();
    boolean systemAppInstalled;
    try {//from   www .j a  va2s  . co m
        packageManager.getPackageInfo(Constants.SYSTEM_SERVICE_PACKAGE, PackageManager.GET_ACTIVITIES);
        systemAppInstalled = true;
    } catch (PackageManager.NameNotFoundException e) {
        systemAppInstalled = false;
    }
    return systemAppInstalled;
}

From source file:com.google.android.gms.common.GooglePlayServicesUtil.java

public static boolean m110b(PackageManager packageManager) {
    synchronized (Au) {
        if (At == -1) {
            try {
                if (m107a(packageManager.getPackageInfo(GOOGLE_PLAY_SERVICES_PACKAGE, 64), Ap[1]) != null) {
                    At = 1;/*from   ww w. j  av  a 2 s  .  com*/
                } else {
                    At = 0;
                }
            } catch (NameNotFoundException e) {
                At = 0;
            }
        }
    }
    return At != 0;
}

From source file:biz.bokhorst.xprivacy.Util.java

public static Version getProEnablerVersion(Context context) {
    try {//from   w  w w.  j  av a  2s.  c o m
        String proPackageName = context.getPackageName() + ".pro";
        PackageManager pm = context.getPackageManager();
        PackageInfo pi = pm.getPackageInfo(proPackageName, 0);
        return new Version(pi.versionName);
    } catch (NameNotFoundException ignored) {
    } catch (Throwable ex) {
        Util.bug(null, ex);
    }
    return null;
}

From source file:biz.bokhorst.xprivacy.Util.java

public static int getSelfVersionCode(Context context) {
    try {//from   ww w . j  a  v  a  2 s .co m
        String self = Util.class.getPackage().getName();
        PackageManager pm = context.getPackageManager();
        PackageInfo pInfo = pm.getPackageInfo(self, 0);
        return pInfo.versionCode;
    } catch (NameNotFoundException ex) {
        Util.bug(null, ex);
        return 0;
    }
}

From source file:biz.bokhorst.xprivacy.Util.java

public static String getSelfVersionName(Context context) {
    try {// w w w.j a  va 2s.com
        String self = Util.class.getPackage().getName();
        PackageManager pm = context.getPackageManager();
        PackageInfo pInfo = pm.getPackageInfo(self, 0);
        return pInfo.versionName;
    } catch (NameNotFoundException ex) {
        Util.bug(null, ex);
        return null;
    }
}

From source file:com.nxp.ltsm.ltsmclient.tools.Utils.java

public static String shaSignature(String pkg, Context context) {
    String TAG = "Utils:createSha";
    String hashString = "";
    PackageManager pm = context.getPackageManager();
    try {//from ww  w . ja  v a 2 s .c o m
        PackageInfo info = pm.getPackageInfo(pkg, PackageManager.GET_SIGNATURES);
        Signature[] sigs = info.signatures;
        for (int i = 0; i < sigs.length; i++) {
            hashString = hashString + sigs[i].toCharsString();
        }
        Log.i(TAG, "pkg " + pkg);
        Log.i(TAG, "hashString " + hashString);
        if (hashString == "") {
            return hashString;
        }
        return makeShaSignature(hashString);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:com.felkertech.n.ActivityUtils.java

/**
 * Opens the correct intent to start editing the channel.
 *
 * @param activity The activity you're calling this from.
 * @param channelUrl The channel's media url.m
 *//*from   ww w . j  a  v a  2 s . c om*/
public static void editChannel(final Activity activity, final String channelUrl) {
    ChannelDatabase cdn = ChannelDatabase.getInstance(activity);
    final JsonChannel jsonChannel = cdn.findChannelByMediaUrl(channelUrl);
    if (channelUrl == null || jsonChannel == null) {
        try {
            Toast.makeText(activity, R.string.toast_error_channel_invalid, Toast.LENGTH_SHORT).show();
        } catch (RuntimeException e) {
            Log.e(TAG, activity.getString(R.string.toast_error_channel_invalid));
        }
        return;
    }
    if (jsonChannel.getPluginSource() != null) {
        // Search through all plugins for one of a given source
        PackageManager pm = activity.getPackageManager();

        try {
            pm.getPackageInfo(jsonChannel.getPluginSource().getPackageName(), PackageManager.GET_ACTIVITIES);
            // Open up this particular activity
            Intent intent = new Intent();
            intent.setComponent(jsonChannel.getPluginSource());
            intent.putExtra(CumulusTvPlugin.INTENT_EXTRA_ACTION, CumulusTvPlugin.INTENT_EDIT);
            Log.d(TAG, "Editing channel " + jsonChannel.toString());
            intent.putExtra(CumulusTvPlugin.INTENT_EXTRA_JSON, jsonChannel.toString());
            activity.startActivity(intent);
        } catch (PackageManager.NameNotFoundException e) {
            new MaterialDialog.Builder(activity)
                    .title(activity.getString(R.string.plugin_not_installed_title,
                            jsonChannel.getPluginSource().getPackageName()))
                    .content(R.string.plugin_not_installed_question).positiveText(R.string.download_app)
                    .negativeText(R.string.open_in_another_plugin)
                    .callback(new MaterialDialog.ButtonCallback() {
                        @Override
                        public void onPositive(MaterialDialog dialog) {
                            super.onPositive(dialog);
                            Intent i = new Intent(Intent.ACTION_VIEW);
                            i.setData(Uri.parse("http://play.google.com/store/apps/details?id="
                                    + jsonChannel.getPluginSource().getPackageName()));
                            activity.startActivity(i);
                        }

                        @Override
                        public void onNegative(MaterialDialog dialog) {
                            super.onNegative(dialog);
                            openPluginPicker(false, channelUrl, activity);
                        }
                    }).show();
            Toast.makeText(activity, activity.getString(R.string.toast_msg_pack_not_installed,
                    jsonChannel.getPluginSource().getPackageName()), Toast.LENGTH_SHORT).show();
            openPluginPicker(false, channelUrl, activity);
        }
    } else {
        if (DEBUG) {
            Log.d(TAG, "No specified source");
        }
        openPluginPicker(false, channelUrl, activity);
    }
}

From source file:biz.bokhorst.xprivacy.Util.java

@SuppressLint("DefaultLocale")
public static boolean hasValidFingerPrint(Context context) {
    try {//ww  w .jav a 2  s  .  c om
        PackageManager pm = context.getPackageManager();
        String packageName = context.getPackageName();
        PackageInfo packageInfo = pm.getPackageInfo(packageName, PackageManager.GET_SIGNATURES);
        byte[] cert = packageInfo.signatures[0].toByteArray();
        MessageDigest digest = MessageDigest.getInstance("SHA1");
        byte[] bytes = digest.digest(cert);
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < bytes.length; ++i)
            sb.append((Integer.toHexString((bytes[i] & 0xFF) | 0x100)).substring(1, 3).toLowerCase());
        String calculated = sb.toString();
        String expected = context.getString(R.string.fingerprint);
        return calculated.equals(expected);
    } catch (Throwable ex) {
        bug(null, ex);
        return false;
    }
}

From source file:tr.com.turkcellteknoloji.turkcellupdater.Utilities.java

static boolean isPackageInstalled(Context context, String packageName, int minVersionCode) {
    checkArgumentNotNull("context", context);
    final PackageManager packageManager = context.getPackageManager();
    if (packageManager == null) {
        throw new IllegalStateException("packageManager is null.");
    }/*www  .ja  v  a 2s  .c  om*/
    PackageInfo pi = null;
    try {
        pi = packageManager.getPackageInfo(packageName, 0);
    } catch (NameNotFoundException e) {
        return false;
    }

    return pi != null && pi.versionCode >= minVersionCode;
}

From source file:com.att.android.arodatacollector.utils.AROCollectorUtils.java

/**
 * Retrieves overall information about the specified application package
 * /*  w  w  w . j  a  v a2 s .c o m*/
 * @param pm
 *            The package manager instance.
 * @param name
 *            The package name.
 * 
 * @return Returns information about the package or null if the package
 *         could not be successfully parsed.
 */
public static PackageInfo getPackageInfo(PackageManager pm, String name) {
    PackageInfo ret = null;
    try {
        ret = pm.getPackageInfo(name, PackageManager.GET_ACTIVITIES);
    } catch (NameNotFoundException e) {
        AROLogger.e(TAG, "Exception in getPackageInfo" + e);
    }
    return ret;
}