Forum Xamarin.Android

Announcement:

The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

Multiple File Upload in WebView

I am currently using a webview where I am allowing user to select multiple files from phone Storage. The issue is that the user is not able to select multiple files at once. He has to select one file at a time. I am stuck here. This is what I have implemented so far :

private Action<int, Result, Intent> _resultCallback; public void StartActivity(Intent intent, int requestCode, Action<int, Result, Intent> resultCallback) { _resultCallback = resultCallback; StartActivityForResult(intent, requestCode); } protected override void OnActivityResult(int requestCode, Result resultCode, Intent data) { App.fileSwitchCounter = true; base.OnActivityResult(requestCode, resultCode, data); if (_resultCallback != null) { _resultCallback(requestCode, resultCode, data); _resultCallback = null; } }

`private void OnActivityResult(int requestCode, Result resultCode, Intent data)
{
if (data != null)
{
if (requestCode == FILECHOOSER_RESULTCODE)
{
if (null == mUploadMessage || data == null)
return;
mUploadMessage.OnReceiveValue(WebChromeClient.FileChooserParams.ParseResult((int)resultCode, data));
mUploadMessage = null;
}
}
}

        [Android.Runtime.Register("onShowFileChooser", "(Landroid/webkit/WebView;Landroid/webkit/ValueCallback;Landroid/webkit/WebChromeClient$FileChooserParams;)Z", "GetOnShowFileChooser_Landroid_webkit_WebView_Landroid_webkit_ValueCallback_Landroid_webkit_WebChromeClient_FileChooserParams_Handler")]
        public override bool OnShowFileChooser(Android.Webkit.WebView webView, IValueCallback filePathCallback, FileChooserParams fileChooserParams)
        {
            var appActivity = Xamarin.Forms.Forms.Context as MainActivity;
            mUploadMessage = filePathCallback;
            Intent chooserIntent = fileChooserParams.CreateIntent();
            chooserIntent.PutExtra(Intent.ExtraAllowMultiple,true);
            appActivity.StartActivity(chooserIntent, FILECHOOSER_RESULTCODE, OnActivityResult);
            return true;
        }`

Best Answer

Answers

Sign In or Register to comment.