android webview文件上传不起作用

时间:2011-09-16 19:33:34

标签: android file upload webview

  

可能重复:
  File Upload in WebView

我有一个高级WebView,需要允许用户从他们的设备上传图像或文件。代码没有给出任何错误,但它也没有工作。任何帮助表示赞赏。

private ValueCallback<Uri>                      mUploadMessage;
private final static int FILECHOOSER_RESULTCODE = 1;
@Override
protected void onActivityResult(int requestCode, int resultCode,
        Intent intent) {
    if (requestCode == FILECHOOSER_RESULTCODE) {
        if (null == mUploadMessage)
            return;
        Uri result = intent == null || resultCode != RESULT_OK ? null
                : intent.getData();
        mUploadMessage.onReceiveValue(result);
        mUploadMessage = null;
    }
}

class MyWebChromeClient extends WebChromeClient {


    public void openFileChooser(ValueCallback<Uri> uploadMsg) {

        mUploadMessage = uploadMsg;
        Intent i = new Intent(Intent.ACTION_GET_CONTENT);
        i.addCategory(Intent.CATEGORY_OPENABLE);
        i.setType("image/*");
        RunHTML5WebView.this.startActivityForResult(
                Intent.createChooser(i, "Image Browser"),
                FILECHOOSER_RESULTCODE);
    }
}

0 个答案:

没有答案