I am trying to add my app version to the app. Below is my code
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@color/white">
<PreferenceCategory android:title="Version">
<EditTextPreference
android:key="@string/version"
/>
</PreferenceCategory>
</PreferenceScreen>
Fragment
import com.example.thumbsol.accuratesurvey.BuildConfig;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String verName = BuildConfig.VERSION_NAME;
int verCode = BuildConfig.VERSION_CODE;
// Load the preferences from an XML resource
addPreferencesFromResource(R.xml.preferences);
version = (EditTextPreference)findPreference(getString(R.string.version));
version.setText(verName);
}
GUI
Update 1
Below is my gradle
defaultConfig {
applicationId "com.example.thumbsol.accuratesurvey"
minSdkVersion 19
targetSdkVersion 33
versionCode 3
versionName "3.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
It doesn't show any version name. Although I have debugged the code and checked it.
Any help would be highly appreciated.
