WebView
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
検索
|
最終更新
|
ヘルプ
|
ログイン
]
開始行:
[[Android]]
&color(red){※前提条件:本情報はAndroid Studio 4.2.2を基づ...
#contents
* 保证URL不会在系统的浏览器中打开 [#z005272a]
#codeprettify{{
WebView webView = root.findViewById(R.id.webViewHome);
webView.setWebViewClient(new WebViewClient());
webView.setWebChromeClient(new WebChromeClient());
webView.getSettings().setSupportMultipleWindows(false);
webView.getSettings().setJavaScriptCanOpenWindowsAutomati...
}}
* WebView与网页数据交互 [#t25627e6]
#codeprettify{{
// 打开开关,设置与Js交互的权限
webSettings.setJavaScriptEnabled(true);
WebView.addJavascriptInterface(new JSBridge(),"bridge");
}}
#codeprettify{{
public class JSBridge {
// @JavascriptInterface 必须加上
@android.webkit.JavascriptInterface
public void print(String msg) {
// 在合适的地方,比如点击事件处理中
android.content.Intent intent = new android.conte...
// 替换为实际的抖音唤起链接
System.out.println(msg);
try {
startActivity(intent);
} catch (Exception ex) {
// 处理无法唤起的情况,比如提示用户未安装等
//System.out.println(msg);
ex.printStackTrace();
}
}
}
}}
html里面
#codeprettify{{
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>title</title>
<script>
function callAndroid(){
bridge.print("传去android的消息");
}
</script>
</head>
<body>
<button type="button" id="button1" onclick="callAndroid()...
</body>
</html>
}}
#hr();
コメント:
#comment_kcaptcha
終了行:
[[Android]]
&color(red){※前提条件:本情報はAndroid Studio 4.2.2を基づ...
#contents
* 保证URL不会在系统的浏览器中打开 [#z005272a]
#codeprettify{{
WebView webView = root.findViewById(R.id.webViewHome);
webView.setWebViewClient(new WebViewClient());
webView.setWebChromeClient(new WebChromeClient());
webView.getSettings().setSupportMultipleWindows(false);
webView.getSettings().setJavaScriptCanOpenWindowsAutomati...
}}
* WebView与网页数据交互 [#t25627e6]
#codeprettify{{
// 打开开关,设置与Js交互的权限
webSettings.setJavaScriptEnabled(true);
WebView.addJavascriptInterface(new JSBridge(),"bridge");
}}
#codeprettify{{
public class JSBridge {
// @JavascriptInterface 必须加上
@android.webkit.JavascriptInterface
public void print(String msg) {
// 在合适的地方,比如点击事件处理中
android.content.Intent intent = new android.conte...
// 替换为实际的抖音唤起链接
System.out.println(msg);
try {
startActivity(intent);
} catch (Exception ex) {
// 处理无法唤起的情况,比如提示用户未安装等
//System.out.println(msg);
ex.printStackTrace();
}
}
}
}}
html里面
#codeprettify{{
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>title</title>
<script>
function callAndroid(){
bridge.print("传去android的消息");
}
</script>
</head>
<body>
<button type="button" id="button1" onclick="callAndroid()...
</body>
</html>
}}
#hr();
コメント:
#comment_kcaptcha
ページ名: