JS调用android
2015-11-27 10:43
357 查看
package net.sourceforge.simcpux;
import com.groupfly.wzwsy.R;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.webkit.JavascriptInterface;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.widget.Toast;
public class myWebview extends Activity {
private WebView webview;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.zy);
webview = (WebView) findViewById(R.id.webview);
webview.getSettings().setJavaScriptEnabled(true); // 是否支持js
webview.addJavascriptInterface(new MyObject(this), "MyObject");
webview.setWebChromeClient(new WebChromeClient());
webview.loadUrl("https://www.baidu.com/");
}
public class MyObject {
private Context mContext;
public MyObject(Context mContext) {
this.mContext = mContext;
}
@JavascriptInterface
public void getGotoShopName(String content){
Toast.makeText(mContext, content, 3).show();
}
}
}
import com.groupfly.wzwsy.R;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.webkit.JavascriptInterface;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.widget.Toast;
public class myWebview extends Activity {
private WebView webview;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.zy);
webview = (WebView) findViewById(R.id.webview);
webview.getSettings().setJavaScriptEnabled(true); // 是否支持js
webview.addJavascriptInterface(new MyObject(this), "MyObject");
webview.setWebChromeClient(new WebChromeClient());
webview.loadUrl("https://www.baidu.com/");
}
public class MyObject {
private Context mContext;
public MyObject(Context mContext) {
this.mContext = mContext;
}
@JavascriptInterface
public void getGotoShopName(String content){
Toast.makeText(mContext, content, 3).show();
}
}
}
相关文章推荐
- android 5.0及以上,seekbar thumb 透明效果出现父布局背景颜色的解决方法
- android 休眠唤醒机制分析(一)
- Android学习笔记(四):Volley的使用
- android studio里面的svn基本使用
- android中shape、selector、color
- Android防止重复点击深入
- Jenkins+ Gradle +Lint对Android工程源码进行静态代码分析
- Android 控件布局常用属性
- Android入门:增删改查通讯录
- Android Studio 配置Android Annotation
- Android imageview帧动画 监听结束
- Android布局属性说明
- Android之SurfaceView学习(一)
- Android登录模块原理及实现
- android中getSystemService通过系统提供的Manager接口来访问及设置服务数据
- Android项目:proguard混淆第三方jar.
- 序列化接口:Serializable 、Parcelable
- Android项目:proguard混淆第三方jar.
- Android项目:proguard混淆第三方jar.
- Android项目:proguard混淆第三方jar.