I'm developing an application that uses about 150 small HTML pages (up to 25-30kb, actively used by WebView).
My question is how to save this kind of data on Android device ?
Maybe XML or SQLite......
Thanks
Put all the pages in Assets folder. They will be packed together in the apk and access them as below:
webview.loadUrl("file:///android_asset/your_html_page.html");
You can write them at runtime into a specific directory in the sdcard (if present) and load them from it when you want...
Related
I have a website that I'd like to load in WebView. However I have also files (such as images, *css, *js and so on) in assets folder that are needed to open that website. Is it possible to, while loading my website, use as much data from assets as possible and download all the rest from Internet in order to make my site load faster?
For example let's assume that my website needs two image files for proper looking: A and B. I have the A file in assets, but I haven't B at all. Is it possible to make WebView display website with A file from assets folder and B fetched from Internet?
It does depend on the complexity of your website, but assuming it's capable of running offline…
You could download the online content and store it locally in the same folder as the offline content. Then open it. So long as all the references in any downloaded script files are relative you shouldn't have a problem.
You might need to copy the local assets content from a read-only location to a read-write-location, but you could do that on first running the app.
can we add the html and java script code anywhere other than assets folder in android which will used in web View, and it cannot be a URL also since it should work offline, because when we place the .html,java script etc in assets it can be easily found when we unzip the apk.
Kindly advice me in this regard.
Thanks
Nagendra.
You can put them in drawable or values folder as well.
Yes you can put them in /drawables/raw folder and you can access them like mentioned in Load html files from raw folder in web view. If you talk about unzipping or even reverse engineering for that matter, the java code, layout files all can be reverse engineered, sometimes even if you obfuscate the code. I would suggest you to store all sensitive data on a servers and then get it on runtime in the app.
I try to make Webview from to display application/x-shockwave-flash embed element in my app, but i have blank gray screen on emulator and white on device. There are many topics about this problem but any1 really solved.
I explore log of simillar app and see: file//android_asset/index.html. So question... this static file or i can get it from web or modify it.
I trying get my data video.loadDataWithBaseURL() from web, but can i have that data from local storage?
Maybe I said something wron but it's look for me like 'convert web data to local'?? Can some one help my in my problem or explain in this question.
Thank you.
file://android_asset/ is a way that allows android apps access assets by a network-based URI. But assets represent neither local nor online files, they are packed into your apk. Put any files in assets folder in a android project and they will be packed into the apk file by the builder.
I created a rudimentary browser with help of a WebView.
When I visit a website (containing some text and a few images), the cache directory in /data/data/com.mayexample/cache/webViewCacheChromium gets filled with a few files called index, data_0, data_1, data_2, f_00001, f_00002 etc.
I was wondering, what's the format of these files, what do they contain? I thought about "so, a few of these files surely have to be the website's images then" and tried opening them in a file manager (open as image). But whatever file I pick, the process says "Failed loading!". Even if I rename some of them to .jpg, still I can't open anything.
I have read on the internet that this worked for some people though (look at Android WebView - Load Images from cache, it's exactly what I want to do), but I can't do anything with the cache's files.
Do you know a way to open webview cache files? Doesn't one file represent a corresponding cached image for example?
What I really want to achieve (once I understand the structure of the cache files) is to programmatically fetch images of the webview from it's cache, like the author of the link posted above (unfortunately this posting's answers don't help much)
Thanks!
The cached files might be one of the CSS, or JS/image/html types. On earlier Android releases, one cached file maps exactly one CSS or JS/image/html file.
As far as I know the Browser engine (actually the HTTP module) maintains such cached files in a URL-to-HashKey manner. So what you found (such as "4f42185de3a3a461_1") may be associated with any web resource files such as JS/CSS/images/HTML, etc.
I remember WebView used to store such URL-to-HashKey mapping data in sqlite3 tables in earlier Android versions.
The problem here is you have no idea about the mapping relations so you can hardly retrieve the file you want. A tricky way is to read the AOSP source code then you may be able to know how the generate the HashKey by an unique URL, or you can manipulate the sqlite3 tables, if there are still any on Android 4.4.
I was able to view files in the webViewCacheChromium folder using this tool designed for the Chrome desktop browser:
http://www.nirsoft.net/utils/chrome_cache_view.html
The contents are basically what you'd expect for web cache - images, javascript, css, html.
I am working on a Flex 4.5 app tageting Android. In different views the app needs to load and display images which I have deployed as part of the app.
Where do I put these images? And how do I load them?
I am familiar with #Embed for images, but this doesn't seem to be the correct approach in this case. I also know how to load from the file system, but I really don't know how to include my images as part of the app for distribution.
Thanks if you can help.
Gary
This worked for me in a mobile app that I wrote in Flex:
I have the following files:
src/assets/images/myImage.png
src/myApp.mxml
Inside myApp.mxml I have an image that references the one in the assets:
<s:Image source="../assets/images/myImage.png" />
I have NO idea why I have to go up one directory to make this work as the assets folder is in the same folder as the MXML file... but this is what worked for me.