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;
    }

相关内容

热门资讯

这一现象值得深思!we pok... 这一现象值得深思!we poker辅助器v3.3,impoker辅助,法门教程(真的有挂)-哔哩哔哩...
透视好牌!德普之星有辅助软件吗... 透视好牌!德普之星有辅助软件吗,德普之星怎么设置埋牌(透视)确实有挂(有挂教学)-哔哩哔哩1、德普之...
今日!广东雀神智能插件需要付费... 今日!广东雀神智能插件需要付费吗,小程序微乐斗地主辅助,办法教程(有挂方略)-哔哩哔哩1、广东雀神智...
透视透视挂!德普之星透视辅助软... 透视透视挂!德普之星透视辅助软件是真的吗,德普之星透视辅助软件(透视)竟然有挂(有挂教学)-哔哩哔哩...
据报道!天天贵阳破解版,wep... 据报道!天天贵阳破解版,wepoker插件功能辅助器,方式教程(果真有挂)-哔哩哔哩;在进入wepo...
透视中牌率!德普之星辅助器ap... 透视中牌率!德普之星辅助器app,德普之星的辅助工具介绍(透视)竟然是真的挂(有人有挂)-哔哩哔哩1...
截至发稿!丰城双剑辅助器,小程... 截至发稿!丰城双剑辅助器,小程序雀神雀神智能插件,总结教程(详细教程)-哔哩哔哩1、下载好小程序雀神...
透视脚本!德普辅助器怎么用,德... 透视脚本!德普辅助器怎么用,德普之星透视软件免费入口官网(透视)一直是有挂(有挂解密)-哔哩哔哩1、...
为了进一步!多乐破解游戏盒子破... 为了进一步!多乐破解游戏盒子破解版,微乐小程序自建房辅助下载,机巧教程(有挂秘笈)-哔哩哔哩1、微乐...
透视脚本!德普之星怎么开辅助,... 透视脚本!德普之星怎么开辅助,德普之星怎么开辅助(透视)竟然真的是有挂(有挂功能)-哔哩哔哩一、德普...