Android的web视图,openfilechooser终止 [英] Android webview, openfilechooser termination

查看:219
本文介绍了Android的web视图,openfilechooser终止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的应用程序,让上传图片(画廊或相机)的选项,
我用的WebView和管理,使其发挥作用。

I have a simple application that gives the option to upload an image (gallery or camera), I used webview and managed to make it work.

我有,当我打开openfilechoosr对话框,回来我的应用程序的而不选择的任何文件(通过背部或只需点击我的应用程序的屏幕)出了问题,不是我的应用程序是不是再响应(直到机器人重新启动),当我重新启动它,它显示为空白页。

I have a problem when I'm opening "openfilechoosr" dialog and coming back to my app without choosing any file (via the back or just clicking my app screen), than my app is not responding anymore (until android restart) and when I relaunch it, it appears as a blank page.

一些更多的信息:

每一个我试图打开应用程序,我下了文件选择不选择任何文件时间后,我发现了错误(应用程序将重新启动机器人后再次工作):

The error I'm getting each time I'm trying to open the app after I got out the file chooser without choosing any file (the app will work again after restarting the android):

java.lang.Throwable的:EventHub.removeMessages(INT什么= 107)不
  支持前WebViewCore建立

java.lang.Throwable: EventHub.removeMessages(int what = 107) is not supported before the WebViewCore is set up

我的code:
[MainActivity]

My Code: [MainActivity]

webView = (WebView) findViewById(R.id.webview);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setBuiltInZoomControls(true);
webView.getSettings().setSavePassword(false);
webView.getSettings().setSaveFormData(false);
webView.setWebViewClient(new MyWebViewClient());
webView.setWebChromeClient(new MyWebChromeViewClient());  
webView.loadUrl(url);


private class MyWebViewClient extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }
    }

    private class MyWebChromeViewClient extends WebChromeClient {
        //@Override
        public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType )  {      
             File imageStorageDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "MyApp");
            // Create the storage directory if it does not exist
            if (! imageStorageDir.exists()){
                imageStorageDir.mkdirs();                  
            }
            File file = new File(imageStorageDir + File.separator + "IMG_" + String.valueOf(System.currentTimeMillis()) + ".jpg");  
            imageUri = Uri.fromFile(file); 

            final List<Intent> cameraIntents = new ArrayList<Intent>();
            final Intent captureIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
            final PackageManager packageManager = getPackageManager();
            final List<ResolveInfo> listCam = packageManager.queryIntentActivities(captureIntent, 0);
            for(ResolveInfo res : listCam) {
                final String packageName = res.activityInfo.packageName;
                final Intent intent = new Intent(captureIntent);
                intent.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name));
                intent.setPackage(packageName);
                intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
                cameraIntents.add(intent);
            }


            uploadMessage = uploadMsg; 
            Intent intent = new Intent(Intent.ACTION_GET_CONTENT);  
            intent.addCategory(Intent.CATEGORY_OPENABLE);  
            intent.setType("image/*"); 
            Intent chooserIntent = Intent.createChooser(intent,"Image Chooser");
            chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, cameraIntents.toArray(new Parcelable[]{}));
            activity.startActivityForResult(chooserIntent,  FILECHOOSER_RESULTCODE); 
        }

请咨询。

感谢乔。

推荐答案

我发现这个问题,

忘了添加到的onActivityResult,其中,结果是等于取消的情况下,即0

I forgot to add to the "onActivityResult" the case where the result is equals to "cancel" i.e. 0

这篇关于Android的web视图,openfilechooser终止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆