android_asset not working on Honeycomb?

做~自己de王妃 提交于 2019-11-28 04:28:30

问题


I have a shipping Android application that displays occasional static webpages that are included in the assets folder. I have been displaying these programmatically like:

webView = new WebView(PKBDocument.KnowledgeBook.KBContext);
setContentView(webView);
webView.loadUrl("file:///android_asset/path/to the/file.html");

This works fine for API levels 3 - 9. I just recently received my shiny new Xoom and tried running the same app, and I get an error

The webpage at file:///android_asset/path/to%20the/file.html might be temporarily down or it may have moved permanently to a new web address

So, I started experimenting. The Honeycomb emulator displays these pages just fine, but my actual honeycomb device (running 3.0.1) consistently displays this error. I can read the webpage with AssetManager and then display it using loadDataWithBaseURL(), but then the image links in the web page don't load (presumably because it can't find the path to the image file).

Any idea what changed, and how to handle this?


回答1:


Try removing the space. This project and this project both work fine on my XOOM.




回答2:


For me the problem was that I compiled with maven. With maven your assets should go into src/main/resources/assets and I had them in src/main/resources — which apparently is wrong.

It seems that Honeycomb stricter about this. If you don't use Maven then make a listing of the files in your apk file (it is just as zip file) and check that your assets correcty inside the asset directory:

7z l target/*.jar

7-Zip [64] 9.20  Copyright (c) 1999-2010 Igor Pavlov  2010-11-18
p7zip Version 9.20 (locale=utf8,Utf16=on,HugeFiles=on,8 CPUs)

Listing archive: target/HP45-Droid-5.0.0.jar

--
Path = target/HP45-Droid-5.0.0.jar
Type = zip
Physical Size = 465392

   Date      Time    Attr         Size   Compressed  Name
------------------- ----- ------------ ------------  ------------------------
2012-01-01 19:07:10 D....            0            0  META-INF
2012-01-01 19:07:08 .....          125          102  META-INF/MANIFEST.MF
2012-01-01 19:07:06 D....            0            0  assets
2012-01-01 19:07:06 .....        93692        93629  assets/45bk.jpg
2012-01-01 19:07:06 .....         3467         1408  assets/help.html


来源:https://stackoverflow.com/questions/5365780/android-asset-not-working-on-honeycomb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!