Code example for PackageManager

Methods: getPackageInfogetClass

        PackageManager packageManager = mContext.getPackageManager();
        String foundAppVersionName = null;
        Integer foundAppVersionCode = null;
        try { 
            PackageInfo packageInfo = packageManager.getPackageInfo(mContext.getPackageName(), 0);
            foundAppVersionName = packageInfo.versionName;
            foundAppVersionCode = packageInfo.versionCode;
        } catch (NameNotFoundException e) {
            Log.w(LOGTAG, "System information constructed with a context that apparently doesn't exist.");
        mAppVersionName = foundAppVersionName;
        mAppVersionCode = foundAppVersionCode;
        // We can't count on these features being available, since we need to 
        // run on old devices. Thus, the reflection fandango below... 
        Class<? extends PackageManager> packageManagerClass = packageManager.getClass();
        Method hasSystemFeatureMethod = null;
        try { 
            hasSystemFeatureMethod = packageManagerClass.getMethod("hasSystemFeature", String.class);
        } catch (NoSuchMethodException e) {
Stop searching for code, let great code find you!  Add Codota to your java IDE