4.2及更高版本中的Android Javascript运行问题

时间:2014-02-26 08:45:45

标签: javascript android

我在html的帮助下使用javascript在图像上画线,并在android代码中使用它。它工作正常,直到4.1但从4.2它没有显示我的输出与以前的版本相同。正如建议我在我的java代码中插入javascript注释数据正在接收html正确但不能运行与在Android 4.1中运行相同的方式。在这种情况下该怎么做?

//在oncreate里面

webView = (WebView) findViewById(R.id.webView1);
        WebSettings webSettings = webView.getSettings();
        webSettings.setJavaScriptEnabled(true);

        webView.setBackgroundColor(Color.parseColor("#CCCCCC"));
        //webView.loadUrl(url);
        webView.getSettings().setBuiltInZoomControls(true);
        webView.getSettings().setDefaultZoom(ZoomDensity.FAR);
        webView.getSettings().setSupportZoom(true);


        webView.getSettings().setLoadWithOverviewMode(true);
        webView.getSettings().setUseWideViewPort(true);

        webView.getSettings().setCacheMode(webView.getSettings().LOAD_NO_CACHE);
        webView.getSettings().setRenderPriority(RenderPriority.NORMAL);
        webView.setDrawingCacheEnabled(false);
        webView.setInitialScale(initialScale);  

        //          webView.scrollTo(1256,564);

        //webView.getSettings().setDomStorageEnabled(true);
        //webView.getSettings().setPluginsEnabled(false);

        webView.setWebChromeClient(new WebChromeClient());


        webView.addJavascriptInterface(new JavaScriptInterface(this,pathCoordinateBuilder.toString()), "MyAndroid");

        //webView.scrollBy(1000,1000);

        if (Build.VERSION.SDK_INT >= 11)
            webView.setLayerType(View.LAYER_TYPE_SOFTWARE,null);
                    else
                        webView.setLayerType(View.LAYER_TYPE_HARDWARE, null);

// out of oncreate

public class JavaScriptInterface {
    Context mContext;
    String coordinates;
    JavaScriptInterface(Context c,String s) {
        mContext = c;
        coordinates = s;
    }
    @JavascriptInterface
    public String receiveValue() {
        //do something useful with str
        return coordinates;
    }
    @JavascriptInterface
    public int receiveScrollX() {
        //do something useful with str
        return minPoint.getX();
    }
    @JavascriptInterface
    public int receiveScrollY() {
        //do something useful with str
        return minPoint.getY();
    }

    //add other interface methods to be called from JavaScript
}

0 个答案:

没有答案