Android WebView Combat

Source: Internet
Author: User


WebSettings = Wvshowproduce.getsettings ();
Set the WebView property to be able to execute JavaScript scripts
Websettings.setjavascriptenabled (TRUE);
Settings can access files
Websettings.setallowfileaccess (TRUE);
Setting support Scaling
Websettings.setbuiltinzoomcontrols (FALSE);
Wvshowproduce.getsettings (). setrenderpriority (WebSettings.RenderPriority.HIGH);
Websettings.setcachemode (Websettings.load_default);//Open cache

Websettings.setsupportzoom (FALSE);
Websettings.setallowcontentaccess (TRUE);

Websettings.setjavascriptenabled (TRUE);
Websettings.setusewideviewport (TRUE);//Set this property to scale any scale
Websettings.setloadwithoverviewmode (TRUE);

Websettings.setloadsimagesautomatically (TRUE);
Websettings.setusewideviewport (TRUE);//adjust the picture to fit the webview size
Websettings.setblocknetworkimage (FALSE);
Wvshowproduce.addjavascriptinterface ((class's proxy name), "Ocmodel");

Load Web pages that need to be displayed
Wvshowproduce.loadurl (URL);


Make a jump page
Wvshowproduce.setwebviewclient (New Webviewclient () {
@Override
public boolean shouldoverrideurlloading (WebView view, String URL) {
if (! Textutils.isempty (URL)) {
LOG.I ("img", URL);
Intent intent1 = new Intent (myshowwebviewactivity.this, Myshowwebviewactivity.class);
Intent1.putextra (consts.key_sendentity2activity, URL);
StartActivity (INTENT1);
}
return true;
}

@Override
public void onpagestarted (WebView view, String URL, Bitmap favicon) {
super.onpagestarted (view, URL, favicon);
Rlprogress.setvisibility (view.visible);
}

@Override
public void onpagefinished (WebView view, String URL) {
super.onpagefinished (view, URL);
Rlprogress.setvisibility (View.gone);
Websettings.setblocknetworkimage (FALSE);

if (! Textutils.isempty (title)) {
if (Title.contains ("http") | | | title.contains ("Your domain name") | | title.contains ("local address") | | title.contains ("... ")) {
title = "";
}
Settitle (title);
} else {
Settitle ("");
}
}

@Override
public void Onreceivederror (WebView view, webresourcerequest request, webresourceerror error) {
Super.onreceivederror (view, request, error);
Rlprogress.setvisibility (View.gone);
Toastutil.showshort (Myshowwebviewactivity.this, "There is an error, please try again later");
}
});


Get title
Wvshowproduce.setwebchromeclient (New Webchromeclient () {
@Override
public void Onreceivedtitle (WebView view, String title) {
Super.onreceivedtitle (view, title);
String title_str = title;
if (Title.contains ("http") | | | title.contains ("") | | Title.contains ("") | | Title.contains ("")) {
Title_str = "";
}
MyShowWebViewActivity.this.title = Title_str;
Settitle (title);
}
});


Call JS

String call = "javascript: Method Name ()";
Wvshowproduce.loadurl (call);

JS Call Android

Wvshowproduce.addjavascriptinterface (New Ocmodel (), "Ocmodel");

public class Ocmodel {
share to a conversation
@JavascriptInterface
public void Sharewithcontent (String temp, final string data) {
}




Android WebView Combat

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.