ANDROID_HTML5 Interactive Bullet Box localstorage The whole case of stored value

Source: Internet
Author: User

After more than 2 weeks of time is finally completed is still available Android overall case, share to everyone also hope that they have time to look back at the original study of the tangled mood of Android. The painful experience is that most of the development of Android is on the Internet to find solutions to all kinds of errors and then find a solution this time really very painful now finally can be applied to the project.

PS: Our project when the shell home with Android all the other is HTML5 completed this requires learning to interact with the problem of nonsense no more said also no other want to grumble under O (∩_∩) o~

Import Ksoap2-android-assembly-3.3.0-jar-with-dependencies.jar

Package Com.example.user.testwap;

Import android.content.Intent;
Import Android.net.Uri;
Import Android.os.Bundle;
Import Android.os.Handler;
Import Android.support.v7.app.AlertDialog;
Import android.support.v7.app.AppCompatActivity;
Import Android.util.Log;
Import android.view.KeyEvent;
Import Android.view.Menu;
Import Android.view.MenuItem;
Import Android.webkit.JavascriptInterface;
Import Android.webkit.JsResult;
Import android.webkit.WebChromeClient;
Import Android.webkit.WebView;
Import android.webkit.WebViewClient;
Import Android.widget.Toast;

Import Org.json.JSONArray;
Import Org.json.JSONObject;

Import java.util.List;
Import Java.util.Timer;
Import Java.util.TimerTask;

Import static android.net.uri.*;

public class Mainactivity extends Appcompatactivity {
WebView WebView;
Private Personservice service;
Private Handler Mhandler = new Handler ();
@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Instantiating a WebView object
WebView = new WebView (this);
Service =new Personservice ();
Set the WebView property to be able to execute JavaScript scripts to enable JavaScript support
Webview.getsettings (). Setjavascriptenabled (True);

Enable Localstorage Support
Webview.getsettings (). Setdomstorageenabled (True);
String Appcachepath = Getapplicationcontext (). Getcachedir (). GetAbsolutePath ();
Webview.getsettings (). Setappcachepath (Appcachepath);
Webview.getsettings (). Setallowfileaccess (True);
Webview.getsettings (). Setappcacheenabled (True);

New class name, alias used for interactive access
Webview.addjavascriptinterface (New Javascriptinterface (), "demo");
JS Popup
Webview.setwebchromeclient (New Webchromeclient ());
try {
Set the address of an open page
Webview.loadurl ("http://192.168.16.39:8901/");

Webview.setwebviewclient (New Webviewclient () {
public boolean shouldoverrideurlloading (WebView view, String URL) {
Override this method to indicate that clicking on a link in the Web page or jumping in the current webview does not jump to the browser.
View.loadurl (URL);
return true;
}

});


}
catch (Exception ex)
{
Ex.printstacktrace ();
}
Setcontentview (WebView);
}
Public final class Javascriptinterface {
@JavascriptInterface
public void Getpersonlist () {
Mhandler.post (New Runnable () {
public void Run () {

Webview.loadurl ("Javascript:wave ()");//execute JavaScript function code in HTML layout file--

} catch (Exception e) {
Todo:handle exception
}
}
});
}
@JavascriptInterface
public void Postpay (String data) {
String dd = data;

}
@JavascriptInterface
public boolean Onjsalert (WebView view, string URL, string message, jsresult result) {
if (Message.length ()! = 0) {
Alertdialog.builder Builder = new Alertdialog.builder (mainactivity.this);
Builder.settitle ("from JavaScript"). Setmessage (Message). Show ();
Result.cancel ();
return true;
}
return false;
}
How to call
@JavascriptInterface
public void Call (String mobile) {
Toast.maketext (Mainactivity.this, Mobile, Toast.length_long). Show ();
Intent Intent = new Intent (Intent.action_call, Uri.parse ("Tel:" + mobile));
StartActivity (Intent);
}
}
@JavascriptInterface  //must add this annotation  otherwise the app may not interact with HTML 5

HTML page
<input type= ' button ' onclick= ' Window.demo.call ("335623365") ' value= ' app stored value '/> //Call method that can be called to the app
<script type= "Text/javascript" >

Function Wave () {
alert (123456);

}

</script>

HTML5 page of the JS placed in its own arrangement as long as the HTML page on the line do not put in the app is good

Last added permissions on the Androidmanifest.xml page

<!--networking Privileges--
<uses-permission android:name= "Android.permission.CALL_PHONE"/>
<uses-permission android:name= "Android.permission.INTERNET"/>
<!--read and Write permissions--
<uses-permission android:name= "Android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name= "Android.permission.WRITE_EXTERNAL_STORAGE"/>

This whole case is a collection of localstorage local storage

ANDROID_HTML5 Interactive Bullet box Localstorage stored value overall case

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.