ks32 / CrosswalkNative

Embedded Crosswalk 77 webview based sample project.
95 stars 42 forks source link

addJavaScriptInterface problem #28

Open Jichzhang opened 3 years ago

Jichzhang commented 3 years ago

hi mr ks32

when i use “addJavaScriptInterface” add a interface for my js code then i used the interface like this “window.Android.funtionName” the will tell me “Uncaught TypeError: window.Android.funtionName is not a function”


@SuppressLint({"SetJavaScriptEnabled"})
    private void initWebView(){
        XWalkSettings webSettings = this.webView.getSettings();
        webSettings.setLoadsImagesAutomatically(true);
        webSettings.setSupportSpatialNavigation(true);
        webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
        webSettings.setJavaScriptEnabled(true);
        webSettings.setBuiltInZoomControls(false);
        webSettings.setLoadWithOverviewMode(true);
        webSettings.setUseWideViewPort(true);
        webSettings.setDomStorageEnabled(true);
        XWalkPreferences.setValue("remote-debugging", true);
        webSettings.setAllowFileAccess(true);
        webSettings.setAllowFileAccessFromFileURLs(true);
        webSettings.setAllowUniversalAccessFromFileURLs(true);
        webSettings.setAllowContentAccess(true);
        webSettings.setAppCacheEnabled(true);
        webSettings.setFullscreenSupported(true);
        this.uiClient=new XwalkClientEXT(this,this.webView);
        this.webView.setResourceClient(new XWalkResourceClient(){
            @Override
            public void onLoadFinished(XWalkView view, String url) {
                super.onLoadFinished(view, url);
                setImmersiveMode();
            }
        });
        this.webView.setUIClient(this.uiClient);
        this.webView.clearCache(true);
        this.webView.requestFocus(130);
        this.webView.addJavascriptInterface(new JavaScriptInterface(this),"Android");
        CookieManager.getInstance().setAcceptCookie(true);
        CookieManager.setAcceptFileSchemeCookies(true);
        ((FrameLayout)findViewById(R.id.webview)).addView(this.webView);
    }

@JavascriptInterface
    public String io_sb3FileExists(String file) { return "";}

if("true"==window.Android.io_sb3FileExists(fileName)){}
yyfd2013zy commented 2 years ago

hi,Have you solved this problem?