简体   繁体   English

检查在重新安装应用程序之间资产是否已更改(Android)

[英]Check if assets changed between app reinstall (Android)

Is there a way to see if assets file changed between application reinstall in Android? 有没有办法查看资产文件在Android中重新安装应用程序之间是否发生了更改? Something like md5 or timestamp on whole assets folder (afaik assets are just a zipped file, so maybe it's possible to check just this file for changes?)? 像是整个资产文件夹上的md5或时间戳记(afaik资产只是一个压缩文件,因此也许可以仅检查此文件中的更改?)?

We have an application in which we store configuration xml's in assets folder, then parse them to binary form. 我们有一个应用程序,其中我们将配置xml存储在资产文件夹中,然后将其解析为二进制形式。 As the application is still in development xmls change sometimes. 由于应用程序仍在开发中,因此xmls有时会发生变化。 I'd like to be able to automatically determine that assets changed, so I can 'reload' xmls to binary form. 我希望能够自动确定资产已更改,因此我可以将xmls“重新加载”为二进制格式。 It is always the case, that we have the same amount of xml files which change their content a little so seeing if file list changed is not enough. 总是这样,我们有相同数量的xml文件,它们会稍微更改其内容,因此仅查看文件列表是否更改是不够的。

I know it would be possible to keep a version number, but if possible, I would like to avoid it because it is error prone and would require some discipline from every programmer. 我知道可以保留一个版本号,但是如果可能的话,我想避免使用它,因为它容易出错,并且需要每个程序员都做一些纪律。

EDIT 编辑

Found this answer now: Android assets timestamp 立即找到此答案: Android资产时间戳

As this shows assets timestamp may not be a good idea because it does not reflect asset files timestamp, but rather build time. 如上所示,资产时间戳记可能不是一个好主意,因为它不反映资产文件的时间戳记,而是构建时间。

Take the hash of each file and store along with filename in shared preferences or a file. 取每个文件的哈希值并与文件名一起存储在共享首选项或文件中。 Also store the current versionCode. 还存储当前的versionCode。 On startup, compare the versionCode of the app with the one on disk, and if it has changed, calculate the hashes of your assets and compare with ones on disk. 启动时,将应用程序的versionCode与磁盘上的versionCode进行比较,如果已更改,则计算资产的哈希值并与磁盘上的哈希值进行比较。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM