openFileChooser在从图库中选择图像时打开2次

时间:2012-11-29 11:06:57

标签: android

我实现了webchromeclient的openFileChooser,它打开了一个PHP页面。当我从图库中选择图像时,它会再次打开图库,即图库正在打开两次。

不知道如何摆脱这种情况。

这是我的代码:

public 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/*");
        startActivityForResult(Intent.createChooser(i,"File Chooser"), FILECHOOSER_RESULTCODE);

    }

    public void openFileChooser( ValueCallback<Uri> uploadMsg, String acceptType ) {
        mUploadMessage = uploadMsg;
        Intent i = new Intent(Intent.ACTION_GET_CONTENT);
        i.addCategory(Intent.CATEGORY_OPENABLE);
        i.setType("*/*");
        startActivityForResult(
                Intent.createChooser(i, "File Browser"),
                FILECHOOSER_RESULTCODE);
    }
}

这是onactivityresult:

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;

    } 
}

1 个答案:

答案 0 :(得分:0)

如果您将活动声明为

,请检查清单文件
  

单个实例

然后将在错误的时间调用Activity on result方法。