webview加载网页 怎样将网页数据传递给android
发布网友
发布时间:2022-04-19 19:13
我来回答
共1个回答
热心网友
时间:2023-09-02 10:30
1.Android端代码
public class MainActivity extends Activity {
private static final String LOGTAG = "MainActivity";
@SuppressLint("JavascriptInterface")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final WebView myWebView = (WebView) findViewById(R.id.myWebView);
WebSettings settings = myWebView.getSettings();
settings.setJavaScriptEnabled(true);//设置JS可用
myWebView.addJavascriptInterface(new JsInteration(), "control");//传递对象进行交互
myWebView.setWebChromeClient(new WebChromeClient() {});