Support for HTML5 Sqllite Androidapp

Source: Internet
Author: User

Brief introduction:

Want to build an Android App that supports HTML5;

This HTML5 program requires the use of local storage, especially sqllite;

Created an app with Eclipse, which defaults to creating two XML files that describe the interface in Res/layout, one calling another, and the following code is based on the situation;

 PackageCom.example.helloweb;Importandroid.app.Activity;ImportAndroid.app.ActionBar;Importandroid.app.Fragment;ImportAndroid.content.Context;ImportAndroid.os.Bundle;ImportAndroid.view.LayoutInflater;ImportAndroid.view.Menu;ImportAndroid.view.MenuItem;ImportAndroid.view.View;ImportAndroid.view.ViewGroup;ImportAndroid.os.Build;Importandroid.webkit.WebChromeClient;ImportAndroid.webkit.WebView;Importandroid.webkit.WebSettings;ImportAndroid.webkit.WebStorage.QuotaUpdater; Public classMainactivityextendsActivity {@Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.activity_main); //to support HTML5 local storage using the database (SQLite)String DatabasePath = Getapplicationcontext (). Getdir ("Database", Context.mode_private). GetPath (); if(Savedinstancestate = =NULL) {placeholderfragment fragment=Newplaceholderfragment ();                        Fragment.setdatabasepath (DatabasePath);        Getfragmentmanager (). BeginTransaction (). Add (R.id.container, Fragment). commit (); }} @Override Public BooleanOncreateoptionsmenu (Menu menu) {//inflate the menu; This adds items to the action bar if it is present.getmenuinflater (). Inflate (R.menu.main, menu); return true; } @Override Public Booleanonoptionsitemselected (MenuItem item) {//Handle Action Bar item clicks here. The Action Bar would//automatically handle clicks on the Home/up button, so long//As you specify a the parent activity in Androidmanifest.xml.        intID =Item.getitemid (); if(id = =r.id.action_settings) {            return true; }        return Super. onoptionsitemselected (item); }    /*** A placeholder fragment containing a simple view. * Instantiated as a sub-UI class*/     Public Static classPlaceholderfragmentextendsFragment {String databasepath;  Publicplaceholderfragment () {}//get the database path generated by mainactivity         Public voidSetDatabasePath (String databasepath) { This. DatabasePath =DatabasePath; } @Override PublicView Oncreateview (layoutinflater inflater, ViewGroup container, Bundle savedinstancestate) { View Rootview= Inflater.inflate (R.layout.fragment_main, container,false); //Drag a webview through the IDE into the child UI, so here's a look from the Rootview.WebView WebView =(WebView) Rootview.findviewbyid (R.ID.WEBVIEW1); Webview.setwebchromeclient ( This. Makewebchromeclient ()); WebSettings websettings=webview.getsettings (); Websettings.setjavascriptenabled (true); Websettings.setdatabaseenabled (true); Websettings.setdatabasepath ( This. DatabasePath); //can load local and network resources, load network resources need to configure permissions//Webview.loadurl ("http://www.csdn.net/");Webview.loadurl ("file:///android_asset/demo.html"); returnRootview; }                Privatewebchromeclient makewebchromeclient () {return Newwebchromeclient () {@Override Public voidonexceededdatabasequota (string url, String databaseidentifier, LongCurrentquota,LongEstimatedSize,LongTotalusedquota, Quotaupdater quotaupdater) {Quotaupdater.updatequota (5 * 1024 * 1024);        }            }; }       }}

Configure permissions for the app to access the network (configured in the Androidmanifest.xml file)

<?XML version= "1.0" encoding= "Utf-8"?><Manifest>    <uses-permissionAndroid:name= "Android.permission.INTERNET" />     

<USES-SDK/> <Application></Application></Manifest>

Support for HTML5 Sqllite Androidapp

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.