File chooser in Android WebView not working

244 Views Asked by At

I have implemented a file chooser in an Android WebView and I'm at the point of onActivityResult being called, right after selectiong a file (e.g. an image or a PDF).

This is how I open the file chooser:

    private void openFileChooserImplForAndroid5(ValueCallback<Uri[]> uploadMsg) {

        mUploadMessageForAndroid5 = uploadMsg;
        Intent contentSelectionIntent = new Intent(Intent.ACTION_GET_CONTENT);
        contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE);

        String [] mimeTypes = {"image/*", "application/pdf"};
        contentSelectionIntent.setType("*/*");
        contentSelectionIntent.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes);

        Intent chooserIntent = new Intent(Intent.ACTION_CHOOSER);
        chooserIntent.putExtra(Intent.EXTRA_INTENT, contentSelectionIntent);
        chooserIntent.putExtra(Intent.EXTRA_TITLE, "Select a document");
        startActivityForResult(chooserIntent, FILECHOOSER_RESULTCODE_FOR_ANDROID_5);
    } // similar code is managing non-Android5

Then this is the onActivityResult method being invoked (comments in method signature contain the actual parameters):

public void onActivityResult(int requestCode /*2*/, int resultCode /*-1*/, Intent intent) {
    if (requestCode == FILECHOOSER_RESULTCODE) {
        if (null == mUploadMessage)
            return;
        Uri result = intent == null || resultCode != Activity.RESULT_OK ? null : intent.getData();
        mUploadMessage.onReceiveValue(result);
        mUploadMessage = null;

    } else if (requestCode == FILECHOOSER_RESULTCODE_FOR_ANDROID_5) {
        if (null == mUploadMessageForAndroid5)
            return;
        Uri result;

        if (intent == null || resultCode != Activity.RESULT_OK) {
            result = null;
        } else {
            result = intent.getData(); 
            /*After this instruction, result contains a URI$HierarchicalUri with value content://com.android.providers.media.documents/document/document%3A1000000036*/
        }

        if (result != null) {
            mUploadMessageForAndroid5.onReceiveValue(new Uri[]{result});
        } else {
            mUploadMessageForAndroid5.onReceiveValue(new Uri[]{});
        }
        mUploadMessageForAndroid5 = null;
    }
}

After this code, I have no idea where the selected file content is. The webview is an aspx page like this

                    <telerik:RadGrid ID="RadGridDI" runat="server" AllowPaging="false" OnSelectedIndexChanged="RadGridDI_SelectedIndexChanged"
                        AutoGenerateColumns="False" GridLines="None">
                            <MasterTableView DataKeyNames="Id,DocuId,Filename" ShowHeader="false">
                                <Columns>
                                    <telerik:GridBoundColumn DataField="Filename" HeaderText="Header text" />
                                    <telerik:GridButtonColumn CommandName="Select" Text="View" UniqueName="column" ButtonType="PushButton"/>
                                </Columns>
                            </MasterTableView>
                        </telerik:RadGrid>

How can I end up having the selected file to be processed?

0

There are 0 best solutions below