惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
T
Tailwind CSS Blog
有赞技术团队
有赞技术团队
爱范儿
爱范儿
Engineering at Meta
Engineering at Meta
J
Java Code Geeks
雷峰网
雷峰网
WordPress大学
WordPress大学
L
LangChain Blog
D
DataBreaches.Net
The GitHub Blog
The GitHub Blog
博客园 - 三生石上(FineUI控件)
Microsoft Security Blog
Microsoft Security Blog
P
Proofpoint News Feed
腾讯CDC
GbyAI
GbyAI
罗磊的独立博客
Blog — PlanetScale
Blog — PlanetScale
月光博客
月光博客
F
Fortinet All Blogs
Y
Y Combinator Blog
V
V2EX
A
About on SuperTechFans

HAOTOWN-疯狂减肥带

红米k30s至尊版magisk root - HAOTOWN-疯狂减肥带 网站备案通知 - HAOTOWN-疯狂减肥带 博客被黑了 - HAOTOWN-疯狂减肥带 VUE开发环境配置 - HAOTOWN-疯狂减肥带 NEWCITY2018 简单的typecho主题 - HAOTOWN-疯狂减肥带 一图壁纸安卓版更新日志 - HAOTOWN-疯狂减肥带 Hmusic.js - HAOTOWN-疯狂减肥带 优酷解析API - HAOTOWN-疯狂减肥带 TDPLAYER 脚本 替换ACFUN播放器 - HAOTOWN-疯狂减肥带
WEBAPP开发 - HAOTOWN-疯狂减肥带
haocity · 2017-11-05 · via HAOTOWN-疯狂减肥带

采用js进行互交操作 这里的HWebView大家当作Webview就行 我这里是继承的Webview改了点东西


final HWebView myWebView = (HWebView) findViewById(R.id.myWebView);
WebSettings settings = myWebView.getSettings();
settings.setJavaScriptEnabled(true);
myWebView.addJavascriptInterface(new JsInteration(), "control");
public class JsInteration {
 @JavascriptInterface
   public void toastMessage(String message) {
        Toast.makeText(getApplicationContext(), message, Toast.LENGTH_LONG).show();
    }
}

这样在webview里使用javascript

 function toastMessage(message) {
        window.control.toastMessage(message)
}
toastMessage("hhhhhhhhhh")

安卓函数toastMessage就会被调用
而安卓调用js则更为简单 直接loadUrl即可使用

mWebView.loadUrl("javascript: toastMessage('hhhhhhhhhh')");

如果要使用Web Storage则还要进行储存设置

    settings.setAllowFileAccess(true);
    settings.setDatabaseEnabled(true);
    String dir = this.getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
    settings.setDatabasePath(dir);
    settings.setDomStorageEnabled(true);
    settings.setGeolocationEnabled(true);