User versionName value of AndroidManifest.xml in code

前端 未结 2 1979
别跟我提以往
别跟我提以往 2020-12-07 22:36

The AndroidManifest.xml contains the version name of the application, something like

android:versionName=\"1.0\"

Now the quest

2条回答
  •  没有蜡笔的小新
    2020-12-07 23:01

    If you use ADT and Eclipse:

    String version = getPackageManager().getPackageInfo(getPackageName(), 0).versionName;
    

    If you use Gradle, there is an easier way, since it puts the data into BuildConfig for you:

    String version = BuildConfig.VERSION_NAME;
    

提交回复
热议问题