Build IIS that supports APK download and HTML5 cache (with an ultra-simple Android app) specifically explained

Source: Internet
Author: User

Why do you want to do something that looks unreliable?

Because just learn Android development, not very good control of the Android interface editing and operation, so one of my urgent need to use the HTML5 version number, anyway, this application also need to get a lot of data from the server to display on the phone, that is to say: Must be networked, Ability to work normally, so think about it, anyway, to get the data online, why not directly with my relatively familiar with a bit of HTML to do this application? The province's spending time to learn the control of the Android interface, so it is simple: with a bad way to do an Android program launch welcome interface, the inside page is a full-screen webview, launched after the IISServer to get a Web page display, you can.

But then again, it is better to write a mobile version of the Web site, with the mobile phone built-in browser opened to see it, why still have to spend the trouble to get the app? Because...... The app also has a notification bar alert function, to perform a background service to get alerts provided on the server, etc., so the web version is not enough, so the birth of this weird app.

Good app put on the server, originally figure easy, apk files compressed into a ZIP package, to the customer download, the results ... No language is, a lot of customers have no decompression software on the phone, and will not download and install the decompression software, there is no way, just the IIS plus support apk download features, before the IIS default installation, IIS is not support apk file download, good information to check, add an APK download support is also super simple , I got it handy.

In addition, considering that the use of the web version of the consumption of traffic must be very large, in order to save traffic, it is easy to introduce the HTML5 cache function, but this function of an important file: Cache list file, seemingly with TXT do not use the extension. Have to use that default extension (do not know the other extension line, but it seems to have to set the MIME type of the extension of talent enough), this extension is not the support of IIS default, but also to join manually, fortunately is not complicated.

But the internet did not find the picture instance, so the hand spare, by the way to make a record, grabbed a simple diagram, bong on, this has this article.

For example, with:


APK Download Support:

Extension: . apk

MIME type:application/vnd.android.package-archive


HTML5 Cache Support :

Extension: . manifest

MIME type:text/cache-manifest


APK download Support There is nothing to say, just throw the APK file to the server, the following simple HTML5 cache some points to note:

Examples of 1.HTML5 can be cached:

C.html

<! DOCTYPE html>

stole a lazy, directly with W3school sample to get: http://www.w3school.com.cn/example/html5/html5_html_manifest.html

This example does not know how, it seems that IIS is not set or how, anyway, I test the cache is a failure.

The files referenced in the above file are:

./mymanifest.manifest

./js/demo_time.js

./i/w3school_banner.gif

In order to test FALLBACK: So good not put./html5_html_manifest.html on the server. After the HTML main file is finished, the following is the writing of the cache list file:

2. cache List File Authoring

CACHE manifest# 2014-05-22 v1.0.0cache:./i/w3school_banner.gif./js/demo_time.jsnetwork:login.aspfallback:/. /err/404.html

Above is an example of a complete cache list file that can be seen without increasing./html5_html_manifest.html, in order to test the last fallback effect, the front several tags nothing to say, the network of samples and instructions a lot, Focus on the last failure when the callback page setup, where a line is a unit, a row has two elements, the first is the network normal or file is called when the page, followed by a space and the first element is separated, the second and the element is the network is not available, or the file does not exist the replacement page, the above example, The first element is replaced with a/symbol, which means that all files that are not found or inaccessible when the network is not connected are used with the following file./err/404.html Replace the display. /here is the function of a wildcard, similar to *.


3.webview settings

Of course, if your browser itself supports caching, then you don't have to look at the following content, the above settings, your page can be successfully cached.

But I build is the app that I quote WebView to do, the default cache is closed, then you must set the WebView, otherwise you can not cache: here just give WebView set of code snippet, the specific call WebView sample online A lot of, do not do a redundant statement.

     WebSettings webseting = Mwebview.getsettings ();  Webseting.setjavascriptenabled (TRUE);            JS Support Webseting.setsupportzoom (TRUE); Webseting.setdefaulttextencodingname ("gb2312");  Default code page Mwebview.setscrollbarstyle (view.scrollbars_outside_overlay);          scroll bar mwebview.requestfocus ();          The following are the parts of the cache open and set.    Webseting.setdomstorageenabled (TRUE);           /* If you need to store some simple data that can be solved with Key/value, DOM storage is the perfect solution. * Depending on the scope of action, there are session storage and local storage two, which are used for conversation-level storage (page close disappears) and localized storage (data will never expire unless actively deleted). */Webseting.setappcachemaxsize (1024*1024*8);//Set buffer size, I set the 8M String Appcachedir = this. Getapplicati       Oncontext (). Getdir ("cache", Context.mode_private). GetPath (); Set Cache path Webseting.setappcachepath (appcachedir);   Sets the cache path Webseting.setallowfileaccess (true);   Set the ability to access the file Read file webseting.setappcacheenabled (true); Open App Cache WebsEting.setcachemode (websettings.load_default| Websettings.load_cache_else_network); Set the cache mode to: Update the cache against the HTML5 cache list file and use the cache when the network is not connected.

complete the above 4 steps (the IIS settings are counted one step) and your app is capable of caching the page correctly.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.