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();
}
}
}