public override bool OnShowFileChooser(WebView webView, IValueCallback filePathCallback, FileChooserParams fileChooserParams)
        {
            if (_activity.mUploadMessage != null)
            {
                _activity.mUploadMessage.OnReceiveValue(null);
            }

            _activity.mUploadMessage = filePathCallback;

            try
            {
                File file = createImageFile();
                imageUri = Uri.FromFile(file);

                _activity.mCameraPhotoPath = imageUri;

                Intent captureIntent = new Intent(MediaStore.ActionImageCapture);
                captureIntent.PutExtra(MediaStore.ExtraOutput, imageUri);

                Intent i = new Intent(Intent.ActionGetContent);
                i.AddCategory(Intent.CategoryOpenable);
                i.SetType("image/*");

                Intent chooserIntent = Intent.CreateChooser(i, "이미지 선택기");
                chooserIntent.PutExtra(Intent.ExtraInitialIntents, new IParcelable[] { captureIntent });

                _activity.StartActivityForResult(chooserIntent, MainActivity.FILECHOOSER_RESULTCODE);
            }
            catch (System.Exception e)
            {
                System.Console.WriteLine(e.Message);
            }

            return(true);
        }
예제 #2
0
        public override CloseStatus OnFileChooser(FileChooserParams parameters)
        {
            parameters.SelectedFiles = DireccionDeVideo;
            CloseStatus returnValue = CloseStatus.OK;

            return(returnValue);
        }
        private void RegisterCustomFileUploadActivity(IValueCallback filePathCallback, Intent chooserIntent, string title = "File upload")
        {
            if (Forms.Context is IFormsWebViewMainActivity)
            {
                var appActivity = Forms.Context as IFormsWebViewMainActivity;

                Action <Result, Intent> callback = (resultCode, intentData) =>
                {
                    Console.WriteLine("RegisterCustomFileUploadActivity: Entrato in callback");
                    if (filePathCallback == null)
                    {
                        return;
                    }

                    var result = FileChooserParams.ParseResult((int)resultCode, intentData);
                    filePathCallback.OnReceiveValue(result);
                    Console.WriteLine("RegisterCustomFileUploadActivity: Processato evento callback");
                    appActivity.UnregisterActivityResultCallback(FILECHOOSER_RESULTCODE);
                };

                appActivity.RegisterActivityResultCallback(FILECHOOSER_RESULTCODE, callback);

                ((FormsAppCompatActivity)Forms.Context).StartActivityForResult(Intent.CreateChooser(chooserIntent, title), FILECHOOSER_RESULTCODE);
                Console.WriteLine("RegisterCustomFileUploadActivity: REGISTRATO");
            }
            else
            {
                Console.WriteLine("RegisterCustomFileUploadActivity: Non registrato");
            }
        }
예제 #4
0
            private async Task StartFileChooser(CancellationToken ct, FileChooserParams fileChooserParams)
            {
                var intent = fileChooserParams.CreateIntent();
                //Get an invisible (Transparent) Activity to handle the Intent
                var delegateActivity = await StartActivity <DelegateActivity>(ct);

                var result = await delegateActivity.GetActivityResult(ct, intent);

                _filePathCallback.OnReceiveValue(FileChooserParams.ParseResult((int)result.ResultCode, result.Intent));
            }
        private void RegisterCustomFileUploadActivity(IValueCallback filePathCallback, Intent chooserIntent, string title = "File Chooser")
        {
            if (Forms.Context is IFormsWebViewMainActivity)
            {
                var appActivity = Forms.Context as IFormsWebViewMainActivity;

                Action<Result, Intent> callback = (resultCode, intentData) =>
                {
                    if (filePathCallback == null)
                        return;

                    var result = FileChooserParams.ParseResult((int)resultCode, intentData);
                    filePathCallback.OnReceiveValue(result);

                    appActivity.UnregisterActivityResultCallback(FILECHOOSER_RESULTCODE);
                };

                appActivity.RegisterActivityResultCallback(FILECHOOSER_RESULTCODE, callback);

                ((FormsAppCompatActivity)Forms.Context).StartActivityForResult(Intent.CreateChooser(chooserIntent, title), FILECHOOSER_RESULTCODE);
            }
        }
        public override bool OnShowFileChooser(Android.Webkit.WebView webView, IValueCallback filePathCallback, FileChooserParams fileChooserParams)
        {
            List <string> items = new List <string>()
            {
                AppResources.CameraFileChooser,
                AppResources.GaleriePhotoFileChooser,
                AppResources.DocumentFileChooser
            };
            string selectedItem = items[0];
            int    resultCode   = 0;
            var    appActivity  = context as MainActivity;

            new AlertDialog.Builder(appActivity)
            .SetSingleChoiceItems(items.ToArray(), 0, (sender, e) =>
            {
                selectedItem = items[e.Which];
                System.Diagnostics.Debug.WriteLine(selectedItem);
            })
            .SetPositiveButton("OK", (sender, e) =>
            {
                Intent intent = null;

                if (selectedItem == AppResources.CameraFileChooser)
                {
                    intent = new Intent(MediaStore.ActionImageCapture);
                    CreateDirectoryForPictures();
                    _file = new File(_dir, String.Format("Pic_{0}.png", NoSeqGenerator.Generate()));
                    intent.PutExtra(MediaStore.ExtraOutput, Android.Net.Uri.FromFile(_file));

                    resultCode = CAMERA_RESULTCODE;
                }

                else if (selectedItem == AppResources.GaleriePhotoFileChooser)
                {
                    intent = new Intent(Intent.ActionGetContent);
                    intent.SetType("image/*");
                    resultCode = IMAGE_CHOOSER_RESULTCODE;
                }
                else if (selectedItem == AppResources.DocumentFileChooser)
                {
                    intent     = fileChooserParams.CreateIntent();
                    resultCode = FILECHOOSER_RESULTCODE;
                }
                if (intent != null)
                {
                    intent.PutExtra("PheidiParams", JsonConvert.SerializeObject(FileChooserPheidiParams));
                    mUploadMessage = filePathCallback;
                    appActivity.StartActivity(intent, resultCode, OnActivityResult);
                }
            }).Show();
            return(true);
        }
        public override bool OnShowFileChooser(Android.Webkit.WebView webView, IValueCallback filePathCallback, FileChooserParams fileChooserParams)
        {
            Intent intent = new Intent(Intent.ActionOpenDocument);

            intent.AddCategory(Intent.CategoryOpenable);
            intent.SetType("*/*");
            intent.PutExtra(Intent.ExtraMimeTypes, fileChooserParams.GetAcceptTypes());
            mainActivity.intentCallback = filePathCallback;
            mainActivity.StartActivityForResult(intent, REQUEST_IMAGE_CODE);

            return(true);
        }
예제 #8
0
        // For Android 5.0+
        public override bool OnShowFileChooser(WebView webView, IValueCallback filePathCallback, FileChooserParams fileChooserParams)
        {
            callback(filePathCallback, null, null);

            return(true);
        }
            public override bool OnShowFileChooser(WebView webView, IValueCallback filePathCallback, FileChooserParams fileChooserParams)
            {
                mainActivity.mUploadMessage = filePathCallback;
                Intent i = new Intent(Intent.ActionGetContent);

                i.AddCategory(Intent.CategoryOpenable);
                i.SetType("*/*");
                mainActivity.StartActivityForResult(Intent.CreateChooser(i, "File Chooser"), MainActivity.FILECHOOSER_RESULTCODE);

                return(true);
            }
            public override bool OnShowFileChooser(WebView webView, IValueCallback filePathCallback, FileChooserParams fileChooserParams)
            {
                if (MainActivity.Instance == null)
                {
                    return(false);
                }
                Intent intent = fileChooserParams.CreateIntent();

                MainActivity.Instance.ChooseFile(filePathCallback, intent);
                return(true);
            }
예제 #11
0
            public override bool OnShowFileChooser(Android.Webkit.WebView webView, IValueCallback filePathCallback, FileChooserParams fileChooserParams)
            {
                _filePathCallback = filePathCallback;

                var cancellationDisposable = new CancellationDisposable();

                _fileChooserTaskDisposable.Disposable = cancellationDisposable;

                Task.Run(async() =>
                {
                    try
                    {
                        await StartFileChooser(cancellationDisposable.Token, fileChooserParams);
                    }
                    catch (Exception e)
                    {
                        this.Log().Error(e.Message, e);
                    }
                });

                return(true);
            }
예제 #12
0
 // For Android 5.0+
 public override bool OnShowFileChooser(WebView webView, IValueCallback filePathCallback, FileChooserParams fileChooserParams)
 {
     return(base.OnShowFileChooser(webView, filePathCallback, fileChooserParams));
 }
예제 #13
0
		public override bool OnShowFileChooser(global::Android.Webkit.WebView webView, IValueCallback filePathCallback, FileChooserParams fileChooserParams)
		{
			base.OnShowFileChooser(webView, filePathCallback, fileChooserParams);
			return ChooseFile(filePathCallback, fileChooserParams.CreateIntent(), fileChooserParams.Title);
		}
        public override bool OnShowFileChooser(global::Android.Webkit.WebView webView, IValueCallback filePathCallback, FileChooserParams fileChooserParams)
        {
            base.OnShowFileChooser(webView, filePathCallback, fileChooserParams);

            var chooserIntent = fileChooserParams.CreateIntent();

            RegisterCustomFileUploadActivity(filePathCallback, chooserIntent, fileChooserParams.Title);

            return(true);
        }
        public override bool OnShowFileChooser(WebView webView, IValueCallback filePathCallback, FileChooserParams fileChooserParams)
        {
            this.message = filePathCallback;
            Intent chooserIntent = fileChooserParams.CreateIntent();

            chooserIntent.AddCategory(Intent.CategoryOpenable);
            this.activity.StartActivity(Intent.CreateChooser(chooserIntent, "File Chooser"), filechooser, this.OnActivityResult);
            return(true);
        }
        //File chooser Android 5.0 >
        public override bool OnShowFileChooser(Android.Webkit.WebView webView, IValueCallback filePathCallback, FileChooserParams fileChooserParams)
        {
            WebViewActivity = Xamarin.Forms.Forms.Context as MainActivity;
            WebViewActivity.mUploadMessage = filePathCallback;

            Intent takePictureIntent = new Intent(MediaStore.ActionImageCapture);

            //add temp file path later
            if (WebViewActivity.IsThereAnAppToTakePictures())
            {
                File photoFile = null;
                try
                {
                    photoFile = createImageFile();
                    takePictureIntent.PutExtra("PhotoPath", WebViewActivity.mCameraPhotoPath);
                }

                catch (Exception e)
                { System.Diagnostics.Debug.WriteLine("Unable to create Image File! " + e); }

                if (photoFile != null)
                {
                    WebViewActivity.mCameraPhotoPath = "file:" + photoFile.AbsolutePath;
                    takePictureIntent.PutExtra(MediaStore.ExtraOutput, Uri.FromFile(photoFile));
                }
                else
                {
                    takePictureIntent = null;
                }
            }

            //gallery intent
            Intent galleryIntent = new Intent(Intent.ActionPick, MediaStore.Images.Media.ExternalContentUri);

            Intent[] intentArray;
            if (takePictureIntent != null)
            {
                intentArray = new Intent[] { takePictureIntent };
            }
            else
            {
                intentArray = new Intent[0];
            }

            Intent i = new Intent(Intent.ActionChooser);

            i.PutExtra(Intent.ExtraIntent, galleryIntent);
            i.PutExtra(Intent.ExtraTitle, "Choose Image");
            i.PutExtra(Intent.ExtraInitialIntents, intentArray);

            WebViewActivity.StartActivityForResult(Intent.CreateChooser(i, "File Chooser"), FILECHOOSER_RESULTCODE);

            return(true);
        }
예제 #17
0
 public override bool OnShowFileChooser(WebView arg0, IValueCallback arg1, FileChooserParams arg2)
 {
     Console.WriteLine("onShowFileChooser");
     return(base.OnShowFileChooser(arg0, arg1, arg2));
 }
예제 #18
0
 CloseStatus DialogHandler.OnFileChooser(FileChooserParams parameters)
 {
     return(CloseStatus.CANCEL);
 }
예제 #19
0
        public override bool OnShowFileChooser(global::Android.Webkit.WebView webView, IValueCallback filePathCallback, FileChooserParams fileChooserParams)
        {
            if (fileChooserParams is null)
            {
                throw new ArgumentNullException(nameof(fileChooserParams));
            }

            base.OnShowFileChooser(webView, filePathCallback, fileChooserParams);
            return(ChooseFile(filePathCallback, fileChooserParams.CreateIntent(), fileChooserParams.Title));
        }
예제 #20
0
        public override bool OnShowFileChooser(Android.Webkit.WebView webView, IValueCallback filePathCallback, FileChooserParams fileChooserParams)
        {
            var appActivity = _context as MainActivity;

            mUploadMessage = filePathCallback;
            Intent chooserIntent = fileChooserParams.CreateIntent();

            appActivity.StartActivity(chooserIntent, FILECHOOSER_RESULTCODE, OnActivityResult);
            //return base.OnShowFileChooser (webView, filePathCallback, fileChooserParams);
            return(true);
        }
예제 #21
0
 protected static Android.Net.Uri[] ParseResult(Result resultCode, Intent data)
 {
     return(FileChooserParams.ParseResult((int)resultCode, data));
 }
예제 #22
0
 public override bool OnShowFileChooser(global::Android.Webkit.WebView webView, IValueCallback filePathCallback, FileChooserParams fileChooserParams)
 {
     base.OnShowFileChooser(webView, filePathCallback, fileChooserParams);
     return(ChooseFile(filePathCallback, fileChooserParams.CreateIntent(), fileChooserParams.Title));
 }
예제 #23
0
            public override bool OnShowFileChooser(WebView webView, IValueCallback filePathCallback, FileChooserParams fileChooserParams)
            {
                Logger.Debug(Tag, "onShowFileChooser");
                mActivity.uriCallbacks = filePathCallback;
                Activity activity = mActivity;

                if (activity == null)
                {
                    return(false);
                }
                mActivity.ShowChooseDialog(activity);
                return(true);
            }
예제 #24
0
 public override bool OnShowFileChooser(Android.Webkit.WebView webView, IValueCallback filePathCallback, FileChooserParams fileChooserParams)
 {
     try
     {
         var appActivity = Xamarin.Forms.Forms.Context as MainActivity;
         mUploadMessage = filePathCallback;
         Intent chooserIntent = fileChooserParams.CreateIntent();
         appActivity.StartActivity(chooserIntent);
         //return base.OnShowFileChooser (webView, filePathCallback, fileChooserParams);
         return(true);
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.WriteLine("4 " + ex.Message);
         return(true);
     }
 }
        public override bool OnShowFileChooser(Android.Webkit.WebView webView, IValueCallback filePathCallback, FileChooserParams fileChooserParams)
        {
            ((IWebViewChromeClientActivity)_activity).UploadMessage = filePathCallback;
            Intent i = new Intent(Intent.ActionGetContent);

            i.AddCategory(Intent.CategoryOpenable);
            i.SetType("image/*");
            _activity.StartActivityForResult(Intent.CreateChooser(i, "File Chooser"), FILECHOOSER_RESULTCODE);

            return(true);
        }
예제 #26
0
 protected virtual Object ParseResult(Result resultCode, Intent data)
 {
     return(FileChooserParams.ParseResult((int)resultCode, data));
 }
예제 #27
0
            public override bool OnShowFileChooser(WebView webView, IValueCallback filePathCallback, FileChooserParams fileChooserParams)
            {
                try
                {
                    MUma?.OnReceiveValue(null);

                    MUma = filePathCallback;

                    Intent contentSelectionIntent = Android.OS.Environment.GetExternalStorageState(null).Equals(Android.OS.Environment.MediaMounted) ? new Intent(Intent.ActionPick, MediaStore.Video.Media.ExternalContentUri) : new Intent(Intent.ActionPick, MediaStore.Video.Media.InternalContentUri);
                    contentSelectionIntent.SetType("video/*");
                    contentSelectionIntent.PutExtra("return-data", true); //added snippet
                    contentSelectionIntent.AddFlags(ActivityFlags.GrantReadUriPermission);
                    MActivity.StartActivityForResult(Intent.CreateChooser(contentSelectionIntent, "video Chooser"), Fcr);

                    return(true);
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception);
                    return(false);
                }
            }
 public override bool OnShowFileChooser(WebView webView, IValueCB uploadMsg, FileChooserParams fileChooserParams)
 {
     ChatWindow.ChooseUriArrayToUpload(uploadMsg);
     return(true);
 }
예제 #29
0
        public override bool OnShowFileChooser(Android.Webkit.WebView webView, Android.Webkit.IValueCallback filePathCallback, FileChooserParams fileChooserParams)
        {
            AlertDialog.Builder alertDialog = new AlertDialog.Builder(MainActivity.Instance);
            alertDialog.SetTitle("Take picture or choose a file");
            alertDialog.SetNeutralButton("Take picture", async(sender, alertArgs) =>
            {
                try
                {
                    var photo = await MediaPicker.CapturePhotoAsync();
                    var uri   = await LoadPhotoAsync(photo);
                    filePathCallback.OnReceiveValue(uri);
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"CapturePhotoAsync THREW: {ex.Message}");
                }
            });
            alertDialog.SetNegativeButton("Choose picture", async(sender, alertArgs) =>
            {
                try
                {
                    var photo = await MediaPicker.PickPhotoAsync();
                    var uri   = await LoadPhotoAsync(photo);
                    filePathCallback.OnReceiveValue(uri);
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"PickPhotoAsync THREW: {ex.Message}");
                }
            });
            alertDialog.SetPositiveButton("Cancel", (sender, alertArgs) =>
            {
                filePathCallback.OnReceiveValue(null);
            });
            Dialog dialog = alertDialog.Create();

            dialog.Show();
            return(true);
        }