Quick Snippet:Retrieve info from Manifest.xml

The class PackageInfo exposes all the information contained within the Manifest.xml.

We can easily get package name, version name,version code, last update time, permissions, services...


   try {
        PackageInfo mInfo = getPackageManager().
                           getPackageInfo(getPackageName(),PackageManager.GET_META_DATA);
        Log.i("packageInfo", "PackageName = " + mInfo.packageName);
        Log.i("packageInfo", "VersionName = " + mInfo.versionName);
        Log.i("packageInfo", "VersionCode = " + mInfo.versionCode);
        Log.i("packageInfo", "Last Update Time = " + new Date(mInfo.lastUpdateTime));
        Log.i("packageInfo", "Permission = " + mInfo.permissions);
    } catch (NameNotFoundException e) {
         ......
    }

Popular posts from this blog

Expand and collapse animation

How to centralize the support libraries dependencies in gradle

Android-5: Card and images with rounded corners in Android 4