Android Context Get getPackageVersion(Context c)

Here you can find the source of getPackageVersion(Context c)

Description

get Package Version

License

Open Source License

Declaration

public static String getPackageVersion(Context c) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import android.content.Context;

import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;

import android.os.Build;

import android.util.Log;

public class Main {
    public static String getPackageVersion(Context c) {
        String packageVersion = "";
        try {//from   w  ww .j  a  v  a2 s  . co m
            PackageInfo pInfo = c.getPackageManager().getPackageInfo(
                    c.getPackageName(), 0);
            packageVersion += "I have OpenWatch version "
                    + pInfo.versionName;
            packageVersion += " running on Android API "
                    + String.valueOf(Build.VERSION.SDK_INT) + ".";
        } catch (PackageManager.NameNotFoundException e) {
            Log.e("getPackageVersion",
                    "Unable to read PackageName in RegisterApp");
            e.printStackTrace();
        }
        return packageVersion;
        //USER_AGENT += " (Android API " + Build.VERSION.RELEASE + ")";
    }
}

Related

  1. getNameFromUri(Context context, Uri uri)
  2. getOffset(Context context)
  3. getOpenGLESVersion(final Context context)
  4. getOrientation(Context context, Uri photoUri)
  5. getPackageName(final Context context)
  6. getPackageVersionAsInt(Context c)
  7. getPath(Context context, Uri uri)
  8. getPathFromUri(Context context, Uri uri)
  9. getPermissionLabel(Context context, String permission)