android - 如何获取apk打包发布时间?
PHP中文网
PHP中文网 2017-04-17 17:47:01
0
1
664

如题,我想在应用里显示版本号和版本发布时间,版本号我可以从packageInfo中获取,版本发布时间我想获取应用打包release的时间,请问该如何拿到?

PHP中文网
PHP中文网

认证0级讲师

reply all(1)
PHPzhong

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");
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template