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) {
         ......
    }

Comments

Popular posts from this blog

AntiPattern: freezing a UI with Broadcast Receiver

NotificationListenerService and kitkat

How to centralize the support libraries dependencies in gradle