I have small XML(KB) file in my assets folder. My application draws data from it. But then I have downloaded an updated version of the file I need to replace it somehow and I don't know how to?
Since I am developing on higher API`S I can use DownloadManager class.
Asked
Active
Viewed 3,762 times
2

PovilasID
- 883
- 10
- 34
2 Answers
8
You cannot replace an asset -- assets, like resources, are read-only.
Instead, you will need to adjust your application to detect if you have downloaded the replacement file and use that instead of the asset if it is available.

CommonsWare
- 986,068
- 189
- 2,389
- 2,491
-
I have red a little bit more about the subject and found out that assets are compressed into .apk file but if a folder with specific extension is created it is not compressed. Could I replace a file in such folder and use it to get data out? You see I really do not need both files and the download serves as an update. Just I do not what to update all of the application needlessly. – PovilasID Oct 09 '12 at 07:09
-
@BestBeast: "Could I replace a file in such folder and use it to get data out?" -- no. – CommonsWare Oct 09 '12 at 10:12
-
So is there no reasonable way of updating information containing files? – PovilasID Oct 09 '12 at 19:00
-
@BestBeast: At runtime, from the standpoint of the Android SDK, assets and resources are not files. They are entries in a ZIP archive that is the APK file. That ZIP file, and its contents, are read-only. You can still download your replacement, and you can still use that replacement, but it is *your* job to detect that the replacement exists and to use it if available and use the asset otherwise. – CommonsWare Oct 09 '12 at 19:16
0
My solution is:before i use the assets file i delete all cache file int the path---/data/data/com.yourpackagename.xxx,ofcourse just when the app version is above the old app version.(i saved a SharedPreferences when the app first run.so i can compare the app version). I don't know why the new app's assets resource is exist,but the solution is worked for me!
ps:my app homepage is a webview and the file in the assets,so,i need replace it each app update!

parcool
- 1
-
i know where are the new app's assets resource!if your phone root,you can find it in this path:/system/app/com.yourpackagename.xxx/,it's a apk renamed base.apk! – parcool Oct 09 '15 at 08:46