Android webview 和html 交互
2015-08-31 16:25
447 查看
1.新建一个类,类里面写交互需要的方法:
2.webview设置
3.html调用
public class AndroidForJs { private Context mContext; public AndroidForJs(Context context){ this.mContext = context; } @JavascriptInterface//注意加上注解哦 public void destoryAdDelay(int dealy){ LogUtil.e("AndroidForJs","js---destoryAd"); new Timer().schedule(new TimerTask() { @Override public void run() { AdvHandler.destoryAllAdv(); } }, dealy*1000); } }
2.webview设置
WebView web = new WebView(context); //webview允许使用js web.getSettings().setJavaScriptEnabled(true); //Webview提供的传入js的方法 web.addJavascriptInterface(new AndroidForJs(c), "JavaScriptInterface");
3.html调用
相关文章推荐
- 使用C++实现JNI接口需要注意的事项
- Android IPC进程间通讯机制
- Android Manifest 用法
- [转载]Activity中ConfigChanges属性的用法
- Android之获取手机上的图片和视频缩略图thumbnails
- Android之使用Http协议实现文件上传功能
- Android学习笔记(二九):嵌入浏览器
- android string.xml文件中的整型和string型代替
- i-jetty环境搭配与编译
- android之定时器AlarmManager
- android wifi 无线调试
- Android Native 绘图方法
- Android java 与 javascript互访(相互调用)的方法例子
- android 代码实现控件之间的间距
- android FragmentPagerAdapter的“标准”配置
- Android"解决"onTouch和onClick的冲突问题
- android:installLocation简析
- android searchView的关闭事件