This should be simple but I can't find any info on this...
I simply want to read the package value in the android manifest...
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="THIS"
the reason is simple I have to call context.getResources().getIdentifier(...) and I need the package.
since this code will be reused in other apps I want to make it fool proof when I export it and therefore not have to change the value each time.
anybody knows how to do this ?
Within an Activity, you can simply call getPackageName(). If you should happen to need additional data from the manifest, you can use the PackageInfo class: http://developer.android.com/reference/android/content/pm/PackageInfo.html
Example of setting a TextView to your app version:
try {
PackageManager pm = getPackageManager();
PackageInfo packageInfo = pm.getPackageInfo(this.getPackageName(), 0);
TextView version = (TextView) findViewById(R.id.version);
version.setText(packageInfo.versionName);
} catch (NameNotFoundException e) {}
From your "main" Activity
class:
String package = this.getClass().getPackage().getName();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With