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) {
Connect your IDE to all the code out there  Get Codota for Java