Android 4.2.1, WebView and javascript interface breaks

前端 未结 2 1782
鱼传尺愫
鱼传尺愫 2020-11-28 07:12

I have a webview with added javascript interface which works perfectly on most devices, except for those running Android 4.2.1.

I removed most of the code, and staye

2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-28 07:36

    You have to annotate (@JavascriptInterface) methods in Java class that you want to make available to JavaScript.

        public class JavaScriptInterface {
    Context context;
    
    
    JavaScriptInterface(Context c) {
        context = c;
    }
    
    @JavascriptInterface
    public void edit(String postid) {
        Log.d("myApp", "EDIT!");
        //do stuff
    }    }
    

    Its worked for me. Try out this.

提交回复
热议问题