How get versionName package name versionCode minSdkVersion Android example

How get application version, sdk version, package name defined in the AndroidManifest file programmically Android sample.

MainClass.java onCreate()

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
			setContentView(R.layout.main);
 
         // in onCreate
         PackageInfo pinfo = this.getPackageManager().getPackageInfo(getPackageName(), 0);
         String sVersionCode = pinfo.versionCode; // 1
         String sVersionName = pinfo.versionName; // 1.0
         String sPackName = getPackageName(); // cz.okhelp.my_app
         int nSdkVersion = Integer.parseInt(Build.VERSION.SDK); // 7
         int nSdkVers = Build.VERSION.SDK_INT; // 7
 
       }

AndroidManifes.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="cz.okhelp.my_app"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="7" />
 
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".Add_view_to_tableActivity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
 
    </application>
</manifest>
This entry was posted in Android Examples Code and tagged , , , , , , . Bookmark the permalink.


Comments are closed.



9,109 views