“6hu-16472-myplpan>好协议里的wi % L D 6 F H{ 7-mypl” data-marU K – M y

@Override
prote”6hu”>6 W ?lt;bum 参数message:代 =”6hu”>3 0 ;);
alert(trong>优缺陷“file:///androhu”>{ . t : Z NonClick(View v)lass=”6hu-9284-an class=”6hu-1n class=”hljs-k2″>3、Uncaught =”hljs-built_inhu”>y t P ) (Build.tEnabled( 112837-mypl” dat与J$ H 3 _d j j { y “hljs bash copy-mark=”6hu”>v p A . 0 Flt + N . Z cable”><!DOCT=”6hu”>w V ;“button3”URLct [objetln(v v !span>=X 1

缺陷:J data-mark=”6huOverride
protecypl” data-mark=” data-mark=”6h被JS调用的“javascript:class=”hljs-litlass=”6hu-4402-string”>”butto那就是你没有 ml
mWebView.loa= (WebView) fin-mark=”6hu”>i >9 e ? d ~ H tan>有设置WebChrcted void onCW L X = _ *<>);
mWeb);
// 可以在 url, String m^ j S b J xH
tSettinreturnResult(“”pan>callJS()”
id()-3720-mypl” datn class=”6hu-14llAndro^ W a : ) Z kuilt_in”>return} og valn class=”6hu-10hu-5270-mypl” d18-mypl” data-m先约好的 js 协 ypl” data-mark=
WebSettings wel” data-mark=”6做混杂破例处理 ass=”6hu-10071-?
弹窗
//mypl” data-markspan class=”6hu6hu-9158-mypl” tActivity {
Web/span>body>
verride
public 合约好的协议
//,就调用相应办 /span>s” i B )scgs.setJavaScrip”JS成功调用了A(二) Andrpan class=”6hu- class=”6hu-560eepattributes *class=”hljs-str M # 程到是预先约0ta-mark=”6hu”>/n>(){
//n class=”hljs-s法,对音讯messaById(R.id.webvi” data-mark=”6h、onJsPrompt( u-3672-mypl” daetUrl();
} “button”

过程1:加载JS gs();
webSettin调用的逻辑
Systpl" data-mark="8 _ resuJS经过webview.aash copyable">p < 18) {
mWemark="6hu">g S /p>

过程1:< 0ge-mypl" data-marhtml")加载后, mypl" data-mark6hu">- | ! ] / class="6hu-136ring">"javas2种,下面顺次介 findViewById(RerrideUrlLoadivaluateJavas、onJsConfirm()webSettings = m="6hu-13981-myp0082-mypl" datavascriptInterfaa-mark="6hu">1 缺陷:

per.onCreate(saspan class="6hu>& & $ri

代码混杂问 sck 7"6hu">} ~ l W luper.shouldOvermark="6hu">r 0 ="6hu">{ A g - hljs-string">"j 调用prompt() v160-mypl" data-"6hu-497-mypl" $ q j 3 $ 6 |<"6hu">V d )

lue, JsPromptR MainActivity e">g m M (z rk="6hu">i j L rk="6hu">S | e -11270-mypl" dapan class="6hu-o中增加混杂。 -a-mark="6hu">p >c K - 1 v =SoarYuan<hu">I ) p
O N X Eu">u M Q M + K 来>
&l@ b C M ` p [t;
//点击 
}
</script&blic void onPag L v _  -mypl" data-mar前两个参数t Q .palass="6hu-5000-/span>ile:///ana-mark="6hu">! 页面,就去调用J? s Jg m运用mWebView.lo映射,JS中的mjs :在Android经过如下:javascripspan class="6huan class="6hu-9.html格局放到sr/span>ed(
r 1 h 9 I &z );
}
});"hljs bash copy>iew =(WebView)/strong>

K C ~ [ g /span> 所以阻拦vedInstanceStat Wtaar result=prompn class="hljs-s="6hu">0 % ] *+ D span class="6hu6hu-16244-mypl"JavascriptIntertrong>优缺陷用JS办法有两u">g l Q yif ( au2 j PtS D idity extends Appesult r"buttonrt(p L } v p" data-mark="6hascript.html" 设置与Ja-mark="6hu">D ~ Eoid_a) 3 T !Aenttype4onJn class="hljs-bpan class="6hu-6467-mypl" dataChromeClient
mWd>
<!-- ES.LOLLIPOP) {
能满足大

ypl" data-mark=ndroid需求的办 假如JS想要得到Ad } @c bdata-id="headinass="6hu-9494-ms="hljs-string"nstanceState) {span class="6hus="hljs-literal"6hu-14877-mypl[ H l @rass="hljs-builta-mark="6hu">, d

问题 n>; authority(-690-mypl" datapan>tings = mWespan class="6huan class="hljs-6hu">] Q y E"webview"v b T l" data-mark="6ljs-keyword">els="6hu-16588-myfirm(WebView vit.activity_maink="6hu">O u = B-string">"js去 id="heading-3">行JS办法把回来 an class="hljs-:

S代码的映射le:///anreturn s 由于目标映射,设置传入进 放到src/main/aserface()办法的 n">1、data-mark="6hu"WebView. iH W u Ziass="6hu-14446-办法

JSu-9048-mypl" darceRequest req<"6hu-10846-myplhu-16366-mypl" $ x hats="6hu-6532-myp>n2" onc p Kead&ding()。

过程2:在Androse
{ mWe"6hu">7 O ` P bpan>verrideUrl_ / M Ia-mark="6hu">y ectJ L f I r 32-mypl" data-maw methods must mypl" data-mark办法混合运用, "" + respan> } </scr= D
V>

q w Q ark="6hu">% r $ndroid类:JSKitlass="hljs-titlhu">K 3 5

用的办法

过程2 0 m W ? A

javasm 0 + O ark="6hu">G B oript.html,放到span class="6huan class="6hu-1,需求进行协议 类型的值,操作 ));
N / Ict [oW : ?hu">M 6 j4 data-mark="6hu"mark="6hu"># . adUrl("file:///keepattributes ity = 预先约` v 3 i . 8 f ;/html>
true2345"webvi。处理上述的反 ent(new 

resul6");0 q 7 e/span>llAndroi()="6hu"> ; v - ba-mark="6hu">q mypl" data-markass="6hu-1968-mtle">WebChromeC">setCone>

当 ="6hu">q G % @ pan>ascript的caable"><!DOCTark="6hu">n / toadUr

d和n class="hljs-fg-8">3、运用主 隙,需求选用阻 tentView(R.layoan>JavascriptIneate(Bundle改写,ss="6hu-8432-my"><uri.getAutu况下的交互场景 u-5874-mypl" dad>
</html JS调用Android ss="6hu-17010-mu">7 4 b Yd()"&bView.getSettinu">f & 4mark="6hu"> I +span>ript>
/6hu-9588-mypl" eCallback<Stpyable">webViewjs 回来的成果
}" id=3JS代码后,就会 t;
ark="6hu">v @ Lnction

76-mypl" data-mndoew?arg1=111&X - ^ p 80-mypl" data-m.getQueryParameript()效率更高 span>lo办法")) {
// 过 s="6hu-7980-myp="6hu">d ` * 1< v J ds if (uri.data-mark="6hu"-string">")"eiveValue(Sass="6hu-13282- copyable">在prspan class="6huan>() {
S获取Android办 ata-mark="6hu">rd">if (、运用更简洁。 hu-14592-mypl" an class="6hu-16hu-1428-mypl" evaluateJavascrrk="6hu">r D W ark="6hu">W j 8 class="6hu-142
a mypl" data-mark class="6hu-243 class="hljs-stta-mark="6hu">}tion">点击按钮则调用c题,假如在没有 " data-mark="6hhu-6372-mypl" du-5544-mypl" damark="6hu">_ ! 的回来值杂乱。 ss="6hu-14310-m/span> + resultle">OnClickList>setContu"> Z M R N ,三、参考感terNamesY m r p Ccr {
//该重载办法ue) {
//此处为 ript.html"K m - !Resuljs bash copyab="6hu-3772-myplt_in">return

j 4 ,gspan class="6hundroid办法2<正常,在混杂后 class="hljs-stiew.loadUrl("utf-8过程1:在Andr , 5essa的办法")安全限制问题, ss="hljs-built_()对话框没有回mWebView.的阻拦是JS

d回调给JS的数据ed void onCreatn class="hljs-f*Annotation*
-k)
//

. C z u c -<="6hu">p 8 L);
src/main/assetso取得到 l" data-mark="6data-mark="6hu"s-function">ifrong>详细运用scri的输入框 VERSION.SDK_INTlass="6hu-8092-rd">if (n>y(协议名)判">c >;
}
< result = ascris="6hu-1755-mypi.parse(request ( x b h r . 3-mark="6hu">q Qmark="6hu">H v ldOverrideUrl

Android经p>www.jianshu.c M ls("js"4 a Y;
view.l 的回调办法shouan class="6hu-1ptIevaluateJavascy F p o c V x() {
// 阻 eb1、droid_asset/文 l} *Y pt(WebView viewng result = ndroid的he然后解析即可。rk="6hu">t j ! runk & & Qn>目标等于调用Aeading-0">一、A-string">"utf-8-mark="6hu">T /
// 一般依据sch, String url, Sypl" data-mark=h4>

在JS调用/假如要阻拦URL u-5460-mypl" daark="6hu">^ 6 Re>Carson< class="6hu-358所需求的Url协议ata-mark="6hu">em.out.println< W | H .ipt.html"lt) {
//9 H EebView.getSetti 协议,就解析往 String message3 7 D J x Sr">ashMap<Strinxtends AppComp<下解析参数 edInstanceStatspan class="6hule">WebViewCu U e man class="6hu-8n>);// 设置答应an class="6hu-1ViewById详细运用

+理同办法ettings# Hpan>lt:代表音讯seid=123456" ata-mark="6hu"> data-mark="6huspan class="hljt.activity_o 1 ! * i class="hljs-tit"Android回data-mark="6hu"a-mark="6hu">z u">q ! S N ~ C 摒弃了
//should>an span>);
// JS:jrk="6hu">O ~ 9 ring>()好好的cript:ret//andr;
}
</scritype
=);
button */
document.loc
;
webvie)S N z .程中即可。

>)) {
// 假如sset/javascript6hu-11856-mypl"omeClient,按照 6hu-9954-mypl" ypl" data-mark=pl" data-mark="pan class="hljs;/body>
<ass="6hu-4512-m调用Android需求经过WebbView.lo V j b - o Ypublic clasiew, url);
St% + H)
//假定传入进le"><!DOCTYPrl, messlt办法

% z 7 o 0 T e EO d
协议 定为:file:///an拦的) Uri uri<2、Interfa super.onCreatethods>; } 其url); } @Overrispan>, new Valu6hu">Y k } { !<而loadUrl()的履ority().equalpuhu-12208-mypl" n> super.on* ~ ;ss="heading" dadJavascriptInte即Android 4.4以 bash copyable"pl" data-mark="a-mark="6hu">q tml> cnblogs.com/andass="hljs-keywole"> public clatitle> <sn>uateJavascriper.onCreate(sav法 ); // 设置与J data-mark="6hupl" data-mark="t;title>Soarkid为 js 回来的 V
asc"bView.getSettinan>"")")mark="6hu">L D eme().equals( onRecfunction onclick= pan>esureturn2、经过WebVing">"js://webvi件名.html mWebV承认框,即confi们的音讯内容, 不会使页面ifn> 阻ContentVata-mark="6hu"><String> ta-mark="6hu">t, . H b E & E rAew.
^ y y Q kpl" data-mark="an shouldOverri.html");utton1" 1286-mypl" data>} D e s { Q N #| / M .e>

I | v I vrompt()"lass="hljs-lite的参数,判别是 k="6hu">N / M an S z + j t wttoh3>

Android u-12444-mypl" dlient的shouldOv-5112-mypl" dator: Objet;
&lclass="hljs-lit/span>oid中的he如:刚翻开html
/*约好的d & 7 A - _ re>iew, String6hu-1848-mypl" eading" data-idan>addJ"utf-8"U [ [ o"dempan class="6hu-a-mark="6hu">. U _ ; F d ^ d ofunction<表promt())的内 trong>

/ 一般依据schempan>);] Y / K Lerrihu">? @ = # D >` R KVi">) $ P w o 3 id=O 6hu-8474-mypl" body>
&y ze);
myW825-mypl" data-resu/ z ; I oass="6hu-12903-r <meark="6hu">J C (ata-mark="6hu">dUrl(- ^ i $ - 1 i 50-mypl" data-mK X c T m ;k P ` R @ s i 7s.以下代码设置:X 8 url协议为:js:/class="6hu-7200u-5124-mypl" daener(new Vi!span> super.sho! ] z lidata-mark="6hu"an>ew) findView的办法
"javascspan class="6hu、经过WebChrome互-桥梁WebView"clickp 假如url的协议 t("fRunnablept>
</heapl" data-mark="="6hu-8316-myplta-mark="6hu">7Id(R.id.webview

Android-6968-mypl" dat面JS开端"js://we6hu">i $ k e # - y } =class="hljs-lit成果
}
});
()");
}bView m"js://webvpan>;
webview.l>9 3 h U $ / 6hu-7672-mypl" -3186-mypl" datutf-8"
&g q"* ] ) # b加载JS代码,) K r 8 q f yLoading()阻拦6hu">k e ` z E M }e);
f A ) ^ X ? 8 v O m / a s- S O v J= , . _ Y mpK 5 回调给JS的数据 lass="6hu-14859S办法");>Androing()办法回调n class="6hu-66an>ldOverrideUrding()

[ ` N & w

z mypl" data-mark6hu">C g @x n>);//设置与Js (杂的类 webview.loalass="hljs-stri; // 可以在协议// Android:Maiset/javascript.ass="6hu-4352-mspan class="6hubView view, Webark="6hu">o % .span class="6hurk="6hu">, _ OA C *,。 在混杂文件参"hljs-string">"8 f n B x me | Zect] has no met">4、All WebVieipt:callJSl R="6hu-14256-myp载JS代码,格局规ge进行阻拦

super.onJsAler="6hu-15776-myp,需求做兼容性 -mypl" data-maran class="hljs-javascript.htmlypl" data-mark=onJsAlert(WebVihljs-string">"bcR data-mark="6hu"ark="6hu">= 0 g6hu">J z itate) { sup按钮则调用callA class="6hu-773span class="6hu & = u Handroid_asset/关的代码如下e">Runnable* 0 3 ) lpuew, String url,an class="hljs- data-mark="6huspan> MainActiv class="hljs bass="hljs-string>= l" data-mark="6X q D ; N Y

长处:penWindowsAutom="6hu-6920-mypl Z + O:/button> <65-mypl" data-m m M U San class="6hu-1 } //

两种 riu-17420-mypl" d! P { ^ I ~: 3 u y b h最全面便利、愈 lass="hljs-funcl" data-mark="6lass="6hu-10878 class="6hu-131>WebViewClientbject Obj;/button&g(){ //ut.acttn>))); } % , )"6hu-588-mypl" 映射

1 T 7 Aroid的办法""")"(一)heading" data-inActivity.java avascript(按照以下代码 ypl" data-mark="6hu">W t h + .-mark="6hu">g Gml&bChromeClient(能经过WebView的ass xx.xxan>经过WebViewCb iring>

当该JS经过用的函数以 @a n ipt(m | ) g J

/span>(t"6hu-14454-myplring">"Android lass="6hu-9741-0464-mypl" datas交互的权限 webString> collss="6hu-7482-my容(不是url) /6hu-15320-mypl"ain/asset"Androi054-mypl" data-an class="6hu-9an>gt; </hea M d n 1Q t K (Ork="6hu">* M t e>

ean 300-mypl" data-="6hu-10440-mypeyword">else[ S I * 6hu">F q Z r + class="6hu-7888>{ , q T + b mJct Obj + re> super.onJ B h Q ! tivity_main); mrface()进行目标ta-mark="6hu">0class="hljs bas/345f4d8a5…

" data-mark="6hdefaultVaO 1 7 (<! class="6hu-105 | U 4 uD {
id办 js-string">"And下面JS开端调用ALoading(WebViewor: functionNam处理,重写 //shrk="6hu">u K t valhu">1 Z - ` = Iata-mark="6hu"> H 2lLoatrong>

e); > <titlebSettings webS调用了js办法。 间xx.xxx..7hu">$ B ! |lt is"是在网 lient类的shouldspan>(){ 值 @Ovoolean onJsProm后的Java回调线 Com {e(协议格局) &trincript.h:代表输入框的回gt; <body&gtrfu-mypl" data-marentView(R.layoug, String> pre>test

"jblic class JSKi窗显示"file:///andro class="6hu-131"6hu">q ! O ; ]ass="6hu-4150-mlass="6hu-4214-lt_in">return% c * & o

E ( V 4mark="6hu"> s irnResroid映射的目 法3 ` -7801-mypl" datterface进行注解ass="hljs-keywomark="6hu">2 gmpt(),详细如下ark="6hu">y & Cs="6hu-11390-my(),ain); mWebView allAndroid()办

undle savedI">m c Y C { ( uri.getSchpl" data-mark="g">"js调用了And

详细head&WebView; @OallJS()"ile:///android_-4956-mypl" datmypl" data-mark>Z ~ [则>z p W 1 c 7V G - Mw(R.layou处理办法: 将ta & authoriteral">true( J Gwe-10675-mypl" dab 2ipt目e:///android_as/h3>ss="6hu-16452-mral">trueJSody> </htid_asset/javas8 t W F的问题

N ^ : m= ;

关于A"6hu">7 ; I ) span>(){ alert(ading" data-id=(an class="hljs-ndclickprospan class="hljiew view, Strin">true);">true; 只需求对被JS调 string">"file:/pan>弹窗 mWebViu B # l ; V"="hljs-string">hljs-string">"jerride publi

ickList页加载完成之后 件夹里

k W view, WebResou+ z [ nng>() { @Oveeral">true% @C s 3( span>); String 析参数 ^ 3 6hu-2624-mypl" rk="6hu">6 R Q 6hu-2052-mypl" g &erfacrm()、"javascran> result) { o ew view, Stringading" data-id=ed void onCreatAndroid回调给JSeyword">functios="hljs-built_i目标映射到JS的m Alert()ad>; e().equals(r U e { { W<">callAndroidtrue~ View.post(new <6hu">L Q d B x /span>nCreate(s ta-mark="6hu">@pan>Activity ex" data-mark="6hlert()、confirmdata-mark="6hu"unction">"javascran>set=; 交互的权限 //参an>17或更高,引nction">setCon-9715-mypl" datk="6hu">= Q Arunca10584-mypl" datn class="6hu-43呈现在Android详 ; V _hstrong>

an>ult(""3 - ~ m g"callAndroC n !allv K D @ 70-mypl" data-m" data-id="head处理办法二、开发时遇到mypl" data-markhljs-keyword">f

议上带有参数ta-mark="6hu">6阻拦JS对话框( ass="hljs bash lass="hljs-buil class="6hu-158ljs bash copyabata-mark="6hu">indowsAutomatic

returntrue;();
Setroid中的目标名 参数set议 =a 好好的 ();
假如是阻拦 ass="hljs-strind=+ + W I ="heading-11">2S中的returnResuiew.setWebChroml" data-mark="6调用javion = ureta chars4280-mypl" data());
}
}
typeZew.e"mjf议,就解析往下解de class="hljs ss="6hu-9282-my6hu-10624-mypl""6hu">R { b a 4? Bity_mn class="hljs-b过程1:加载JS代//此处完成,就 avascript)) {
// 过程3ypl" data-mark=amp;arg2=222"v Y R L y | t ebView;
@Overri谢

www.>

P z $ B r d lass="6hu-880-m ! 7 Hddurl, message, r);
{ b } $ ! & : /); // 设置与J协议。假如检测 ass="6hu-12805-an class="6hu-1"6hu-12104-mypl代码,如下: eturn : R k ~ V ]
"<html>
&l" data-mark="6h>

常用 L . A
&l常,将webview操>d n k u 3 8 a<="6hu">- ] ~ H 6hu">= Y / | +<-mark="6hu">n gt;
<title>verride
protect协"js"k="6hu">w M U @k="6hu">U s U X关于Android 4.2pl" data-mark="70-mypl" data-mmark="6hu"> P jl" data-mark="6urlj 拦输入框(原

+ result + <] : ; U ~ 9 l wiew) findViewByspan class="6hu (WebVitspan class="6hurk="6hu">u q - rinA X b [ oid里经过WebVie行则会。

params = ass="6hu-13662-hljs-string">"b.0体系以上现已 mark="6hu">R i >x.JSKit{
publiypl" data-mark=roid-blo…

<(savri.getSchem6hu">2 l K 7 J Ault(js-built_in">re-mark="6hu">[ ZSetting D * f存在aew.loadUrl(;t;hea

假如 0 Y S 5 ,ss="6hu-16464-m);
// 加载JS代 ` B ! R L h F