2

I am trying to display a png file using WebView.loadUrl(string) where the png file is stored inside the zip APK Expansion file in Android. The path to the Expansion file is:

Environment.getExternalStorageDirectory()+"/Android/obb/com.example.myapp/main.1.com.example.myapp.obb";

So I am using the following to display the file mypicture.png

String url = "jar:file:/" + Environment.getExternalStorageDirectory()+"/Android/obb/com.example.myapp/main.1.com.example.myapp.obb!/mypicture.png";

WebView wv;
... // code to setup the webview
wv.loadUrl(url);

I get the error Webpage not available at the link

jar:file://storage/sdcard0/Android/obb/com.example.myapp/main.1.com.example.myapp.obb!/mypicture.png

I know my expansion file is there and contains the png file because I have some test code to extract the png file from the expansion file. The wv.loadUrl(extracted_png_location) displays the png correctly when I point to the extracted png file outside. I just can't get it to display the png file that is inside the zip expansion file.

So the path to the png file inside the zip file must be wrong? Or is it even possible to use loadUrl() directly on a file inside the zip?

Enoch
  • 21
  • 3

2 Answers2

1

It is a good alternative to use JOBB tools to pack expansion file and use StorageManager to mount it. After that the files inside expansion file should be accessible as regular files in the file system. The unpacking of expansion file is not needed in this case.

Aleksei
  • 1,207
  • 1
  • 13
  • 16
0

I have exactly the same problem. My webview content is too large to be delivered within the app, but the zip comming from the expansion download is not accessible via webview, because it needs direct paths.

Using the Zip Lib from google is no option, because it only returns streams and the webview doesn´t work with streams.

the method which loads the data from paths seems to be native implemented, no possibility to override anything.

Unzipping is no option, because you can´t delete the zip file. the app will notice it and start to re-download it, so you need to keep it anyway.

The only solution is writing your own updater which downloads the content directly and unzipped

Marian Klühspies
  • 15,824
  • 16
  • 93
  • 136