Monday, July 12, 2010

Read Package information from Manifest in Android

We can get the package name, version number, version code, permissions, META-DATA like what ever we faced placed in the manifest file can be retrieved using PackageManager.

The code snippet is,

 
public class ReadPackage extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Read package name and version number from manifest
try {
PackageManager manager = this.getPackageManager();
PackageInfo info = manager.getPackageInfo(this.getPackageName(), 0);
Toast.makeText(
this,
"PackageName = " + info.packageName + "\nVersionCode = "
+ info.versionCode + "\nVersionName = "
+ info.versionName + "\nPermissions = "+info.permissions, Toast.LENGTH_SHORT).show();
} catch (Exception e) {
System.out.println(" Exception in onCreate() : e = " + e);
}
}
}

No comments:

Post a Comment

Androidians