AndroidWebview图库和相机图片上传,相机不工作
创始人
2024-10-12 03:30:25
0
  1. 在AndroidManifest.xml文件中添加权限
    
    
    
  1. 在WebViewClient中使用onShowFileChooser()方法接收上传请求
    private ValueCallback mUploadMessage;
    private static final int REQUEST_SELECT_FILE = 100;

    @Override
    public boolean onShowFileChooser(WebView webView, ValueCallback filePathCallback, WebChromeClient.FileChooserParams fileChooserParams) {
        if (mUploadMessage != null) {
            mUploadMessage.onReceiveValue(null);
        }
        mUploadMessage = filePathCallback;
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        if (intent.resolveActivity(webView.getContext().getPackageManager()) != null) {
            File photoFile = null;
            try {
                photoFile = createImageFile();
            } catch (IOException ex) {
            }
            if (photoFile != null) {
                mCapturedImageUri = FileProvider.getUriForFile(webView.getContext(), webView.getContext().getApplicationContext().getPackageName() + ".provider", photoFile);
                intent.putExtra(MediaStore.EXTRA_OUTPUT, mCapturedImageUri);
            } else {
                intent = null;
            }
        }
        Intent i = new Intent(Intent.ACTION_GET_CONTENT);
        i.addCategory(Intent.CATEGORY_OPENABLE);
        i.setType("image/*");
        Intent chooserIntent = Intent.createChooser(i, "Image Chooser");
        if (intent != null) {
            chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Parcelable[]{intent});
        }
        startActivityForResult(chooserIntent, REQUEST_SELECT_FILE);
        return true;
    }

    private File createImageFile() throws IOException {
        String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
        String imageFileName = "JPEG_" + timeStamp + "_";
        File storageDir = webView.getContext().getExternalFilesDir(Environment.DIRECTORY_PICTURES);
        File image = File.createTempFile(imageFileName, ".jpg", storageDir);
        mCameraImagePath = "file:" + image.getAbsolutePath();
        return image;
    }

相关内容

热门资讯

透视计算"wepok... 您好,wepoker代打辅助这款游戏可以开挂的,确实是有挂的,需要了解加微【136704302】很多...
透视科技"拱趴大菠萝... 您好,拱趴大菠萝万能辅助器这款游戏可以开挂的,确实是有挂的,需要了解加微【136704302】很多玩...
透视计算"aapok... 透视计算"aapoker发牌逻辑"详细辅助黑科技教程(靠谱软件);大神普及一款德州ai内幕,确定了a...
透视系统"wepok... 1、透视系统"wepoker新号好一点吗"详细辅助透视教程(私局代打教程);详细教程。2、wepok...
透视安卓版"wepo... 1、透视安卓版"wepokerplus万能挂"详细辅助透明教程(俱乐部辅助器透视)。2、wepoke...
透视黑科技"hhpo... 透视黑科技"hhpoker是内部控制吗"详细辅助解说技巧(透视脚本下载攻略);hhpoker是内部控...
透视黑科技"wepo... 透视黑科技"wepoker轻量版透视方法"详细辅助详细教程(透视脚本免费app攻略)准备好在wepo...
透视了解"aapok... 1、透视了解"aapoker俱乐部靠谱吗"详细辅助透明挂教程(辅助脚本攻略)2、进入游戏-大厅左侧-...
透视了解"hhpok... 透视了解"hhpoker透视方法"详细辅助揭秘攻略(可以挂底牌技巧)1、点击下载安装,微扑克wpk插...
透视app"约局吧开... 透视app"约局吧开挂神器是真的吗"详细辅助第三方教程(有透视方法技巧);最新版2024是一款经典耐...