从WebView捕获图像并且保存的图像始终处于纵向模式

时间:2017-03-09 15:24:13

标签: android webview android-camera-intent

我目前能够捕获图像并将其上传到文件选择器。但是,无论设备的方向如何,图像始终处于横向模式。任何帮助将不胜感激。以下是我目前正在做的缩写示例。

在activityResult中:

switch (requestCode) {
        case FILECHOOSER_RESULTCODE:
            if(mUploadMessage==null)
                return;

            Uri uri=null;
                try{
                    if(resultCode==RESULT_OK)
                        uri=(data==null) ? mCapturedImageURI : data.getData();
                }
                catch(Exception e){
                    Toast.makeText(getApplicationContext(), "activity :"+e, Toast.LENGTH_LONG).show();
                }
            mUploadMessage.onReceiveValue(uri);
            mUploadMessage=null;
            break;

我也在实现一个WebChromeClient。以下是该代码的相关部分:

// openFileChooser for Android 3.0+
                public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType){
                    mUploadMessage=uploadMsg;
                        try{
                            Intent cameraIntent=new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                            File externalDataDir=Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
                            File cameraDataDir=new File(externalDataDir.getAbsolutePath() + File.separator + "browser-photos");
                            cameraDataDir.mkdirs();
                            String mCameraFilePath=cameraDataDir.getAbsolutePath() + File.separator + System.currentTimeMillis() + ".jpg";
                            mCapturedImageURI=Uri.fromFile(new File(mCameraFilePath));

                            cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT,mCapturedImageURI);

                            Intent i=new Intent(Intent.ACTION_GET_CONTENT);
                            i.addCategory(Intent.CATEGORY_OPENABLE);
                            i.setType("image/*");

                            Intent chooserIntent=Intent.createChooser(i, "Image Chooser");
                            chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Parcelable[]{cameraIntent});

                            startActivityForResult(chooserIntent, FILECHOOSER_RESULTCODE);
                        }
                        catch(Exception e){
                            Toast.makeText(getBaseContext(), "Camera Exception:"+e, Toast.LENGTH_LONG).show();
                        }
                }

                // For Android < 3.0
                @SuppressWarnings("unused")
                public void openFileChooser(ValueCallback<Uri> uploadMsg ){
                    openFileChooser(uploadMsg, "");
                }

                // For Android  > 4.1.1
                @SuppressWarnings("unused")
                public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture){
                    openFileChooser(uploadMsg, acceptType);
                }

                public boolean onConsoleMessage(ConsoleMessage cm){
                    onConsoleMessage(cm.message(), cm.lineNumber(), cm.sourceId());
                    return true;
                }

                public void onConsoleMessage(String message, int lineNumber, String sourceID){
                    Log.d("androidruntime", "www.example.com: " + message);
                }
            });     }

0 个答案:

没有答案