public class JavaScriptObject {
Context mContext;
/** Instantiate the interface and set the context */
JavaScriptObject(Context c) {
mContext = c;
}
/** Show a toast from the web page */
@JavascriptInterface // 指定这是js接口
public void showToast(String toast) {
Toast.makeText(mContext, toast, Toast.LENGTH_SHORT).show();
}
}
function showAndroidToast(toast) {
Android.showToast(toast); // 调用这个接口的showToast方法
}