I need to figure out how to get or make a build number for my Android application. I need the build number to display in the UI.
Do I have to do something with
Kotlin example:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.act_signin)
packageManager.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES).apply {
findViewById(R.id.text_version_name).text = versionName
findViewById(R.id.text_version_code).text =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) "$longVersionCode" else "$versionCode"
}
packageManager.getApplicationInfo(packageName, 0).apply{
findViewById(R.id.text_build_date).text =
SimpleDateFormat("yy-MM-dd hh:mm").format(java.io.File(sourceDir).lastModified())
}
}
Don't thank :-)