0webview以及如何实现为imagess选择器打开图库

时间:2016-09-01 09:46:43

标签: android webview gallery jfilechooser

我正在开发一个Android网络应用程序。所以我在Web视图中插入了Web视图并加载了URL。以下是Web视图活动的代码。

MainActivity.java

public class MainActivity extends AppCompatActivity {
WebView editor;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    editor = (WebView) findViewById(R.id.editer_webview);
    WebSettings webSettings = editor.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setPluginState(WebSettings.PluginState.ON);
    webSettings.setAllowFileAccess(true);
    webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
    webSettings.setBuiltInZoomControls(true);
    webSettings.setUseWideViewPort(true);
    webSettings.setLoadWithOverviewMode(true);
    editor.setInitialScale(1);
    editor.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
    editor.setScrollbarFadingEnabled(false);
    editor.setWebViewClient(new WebViewClient());
    editor.setWebChromeClient(new WebChromeClient());

    editor.loadUrl("http://elabprint.com/SampleEditor/");
       }
@Override
public void onBackPressed() {
    if (editor.canGoBack()) {
        editor.goBack();
    } else {
        super.onBackPressed();
    }
}

}

主要问题是Jsp文件中有按钮。当我点击该按钮时,它会要求打开图库。该按钮在谷歌Chrome浏览器中工作正常。但按钮在我的网络应用程序webview中不起作用。 以下是我的jsp页面中的代码。

  <button type="button" class="btn-sm btn-primary" id="fakeBrowse123" onclick="HandleBrowseClick5();">Upload Image</button>
  function HandleBrowseClick5()
        {
            var obj = canvas.getActiveObject();
            if (!obj) {
                alert("Select Object.");
            } else {
                if (obj.isType('image')) {
                    var fileinput = document.getElementById("tempImgLoader");
                    fileinput.click();
                    SelectImg();
                }
            }
        }


        document.getElementById('tempImgLoader').onchange = function handleImage1(e) {
            var files = e.target.files;
            if (files[0].size / 1024 >= 100.00) {
                var reader = new FileReader();
                reader.onload = function (event) {
                    console.log('fdsf');
                    var imgObj = new Image();
                    imgObj.src = event.target.result;

                    imgObj.onload = function () {
                        var wt1 = this.width;
                        var ht1 = this.height;

                        if (wt1 < 150 || ht1 < 150) {
                            alert("low quality image!!!..");
                        }
                        if (wt1 < 550 && ht1 < 400) {
                            canvas11.setWidth(wt1);
                            canvas11.setHeight(ht1);
                        }
                        if (wt1 > 550 && ht1 > 400) {
                            ht2 = 370;
                            wt2 = (wt1 * 370) / ht1;
                            canvas11.setWidth(wt2);
                            canvas11.setHeight(ht2);
                        }
                        if (wt1 < 550 && ht1 > 400) {
                            ht2 = 400;
                            wt2 = (wt1 * 400) / ht1;
                            canvas11.setWidth(wt2);
                            canvas11.setHeight(ht2);
                        }
                        if (wt1 > 550 && ht1 < 400) {
                            wt2 = 550;
                            ht2 = (ht1 * 550) / wt1;
                            canvas11.setWidth(wt2);
                            canvas11.setHeight(ht2);
                        }

                        document.getElementById('openerImg').click();
                        canvas.backgroundColor = '';
                        var height1 = canvas11.height;
                        var width1 = canvas11.width;
                        var image = new fabric.Image(imgObj);
                        image.set({
                            width: width1,
                            height: height1
                        });
                        canvas11.setBackgroundImage(image, canvas11.renderAll.bind(canvas11));
                    };
                };
                reader.readAsDataURL(e.target.files[0]);
            } else {
                alert("Image size must be greater than 100KB");
            }
        };


        function SelectImg() {         // function for select area for cropping image

            var obj = canvas.getActiveObject();
            canvas11.clear();
            canvas11.add(new fabric.Rect({
                left: 5, top: 5,
                width: obj.width / 2,
                height: obj.height / 2,
                fill: 'transparent',
                stroke: '#000000',
                hasRotatingPoint: false,
                strokeDashArray: [5, 5],
                cornerSize: 5,
                padding: 0,
                cornerColor: 'black',
                borderColor: 'white',
                transparentCorners: false
            }));
            canvas11.item(0).setControlsVisibility({
                mt: false, // middle top disable
                mb: false, // midle bottom
                ml: false, // middle left
                mr: false
            });
            canvas11.setActiveObject(canvas11.item(0));
        }

我无法找到在我的应用webview中打开图库的解决方案。我不知道问题出在哪里。在JSp页面或Android项目中遇到问题。

请提供在Android应用webview中访问图像的解决方案。

请帮助我先生

0 个答案:

没有答案