Using Javascript bridge in android

后端 未结 1 1900
眼角桃花
眼角桃花 2020-12-16 04:53

Im just trying to communicate my java app with the content on the webview .

In detail , may be just showing a toast on button click ?

After searching on goo

相关标签:
1条回答
  • 2020-12-16 05:31

    Your methods inside WebAppInterface class are missing the @JavascriptInterface annotation.

    Your WebAppInterface class should be like this,

    public class WebAppInterface {
        Context mContext;
    
        WebAppInterface(Context c) {
            mContext = c;
        }
    
        @JavascriptInterface
        public void showToast(String toast) {
        }
    
        @JavascriptInterface
        public void showDialog(String dialogMsg){
        }
    
        @JavascriptInterface
        public void moveToNextScreen(){
        }
    
    }
    

    Edit

    Don't forget to limit your app to API17+ when loading web content into the WebView, otherwise your App will be vulnerable to attacks. Read @Robert's comment below.

    0 讨论(0)
提交回复
热议问题