Using HTML5 to develop Android (6)---build HTML5 offline applications

Source: Internet
Author: User

Need to provide a cache manifest file to work out all the resources that need to be used offline
For example
Manifest code
1 CACHE MANIFEST2 #这是注释3images/sound-Icon.png4images/Background.png5 clock.html6 Clock.css7 Clock.js8   9 NETWORK:Ten test.cgi One    A CACHE: -style/default. CSS -    the FALLBACK: -/files/projects/projects
1 2 3 HTML5 Offline application update cache mechanism 4 divided into 2 types of manual and Automatic Updates 5 Automatic Updates: 6 Update of cached resource files changes when the cache manifest file itself changes does not trigger an update 7 Manual Update: 8 using Window.applicationcache 9 JS Code
1 if (Window.applicationCache.status = = Window.applicationCache.UPDATEREADY)   { 2     window.applicationCache.update ();    3 }   
On-line status detection
HTML5 provides two ways to detect online:navigator.online (True/false) and online/offline events.

Build offline Apps in Android
Java code
1 //turn on application caching2Websettingssetappcacheenabled (true); 3String dir = This. Getapplicationcontext (). Getdir ("Cache", Context.mode_private). GetPath (); 4 //set the path to the app cache5 Websettings.setappcachepath (dir); 6 //set the mode of the cache7 Websettings.setcachemode (Websettings.load_default); 8 //set the maximum size of the app cache9Websettings.setappcachemaxsize (1024*1024*8); Ten    One //capacity of the extended cache A  Public voidOnreachedmaxappcachesize (Longspaceneeded, -             LongTotalusedquota, Webstorage.quotaupdater quotaupdater) {    -Quotaupdater.updatequota (spaceneeded * 2);  the}

Using HTML5 to develop Android (6)---build HTML5 offline applications

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.