mikebai.com

  • Home
  • dev
  • DotNET
  • M365
  • 搞笑
  • 杂七杂八
  • FocusDict
個人BLOG
it developer
  1. Main page
  2. dev
  3. Main content

webview中js调用java函数

2016-05-05 107hotness 0likes 0comments

JAVA部分

this.wvMeaning.addJavascriptInterface(new JavaScriptInterface(this), "Android");
public class JavaScriptInterface
{
Context mContext;

/**
* Instantiate the interface and set the context
*/
JavaScriptInterface(Context c)
{
mContext = c;
}

/**
* Show a toast from the web page
*/
//annotate the callback method with @JavascriptInterface.
@JavascriptInterface
public void showToast(String toast)
{
Toast.makeText(mContext, toast, Toast.LENGTH_SHORT).show();
}

@JavascriptInterface
public void startFunction()
{
Toast.makeText(TpMeaning.this, "js调用了java函数", Toast.LENGTH_SHORT).show();
runOnUiThread(new Runnable()
{
@Override
public void run()
{
//msgView.setText(msgView.getText() + "\njs调用了java函数");
}
});
}

@JavascriptInterface
public void startFunction(final String str)
{
Toast.makeText(TpMeaning.this, str, Toast.

Tag: Nothing
Last updated:2016-05-05

mikebai

This person is a lazy dog and has left nothing

Like
< Last article
Next article >

COPYRIGHT © 2025 mikebai.com. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang