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.Last updated:2016-05-05