如题,我想在应用里显示版本号和版本发布时间,版本号我可以从packageInfo中获取,版本发布时间我想获取应用打包release的时间,请问该如何拿到?
认证0级讲师
You can set a placeholder under the application tag of the AndroidManifest file, such as
<meta-data android:name="releaseTime" android:value="${RELEASE_TIME}"> </meta-data>
Then when gradle packages, get the time and set this value as follows:
def releaseTime() { return new Date().format("yyyy-MM-dd", TimeZone.getTimeZone("UTC")) } buildType { release { ... manifestPlaceholders = [RELEASE_TIME: releaseTime()] ... } }
Read time in java code
String releaseTime = context.getPackageManager().getApplicationInfo(getPackageName(), PackageManager.GET_META_DATA).metaData.getString("RELEASE_TIME");
You can set a placeholder under the application tag of the AndroidManifest file, such as
Then when gradle packages, get the time and set this value as follows:
Read time in java code