protected override void OnActivityResult(int requestCode, [GeneratedEnum] Result resultCode, Intent data) { base.OnActivityResult(requestCode, resultCode, data); if (requestCode == FILECHOOSER_RESULTCODE) { if (null == this.mUploadMessage) { return; } Android.Net.Uri[] result = null; try { if (resultCode != Result.Ok) { result = null; } else { //Retrieve from the private variable if the intent is null result = data == null ? new Android.Net.Uri[] { mCameraPhotoPath } : new Android.Net.Uri[] { data.Data }; } } catch (System.Exception e) { Toast.MakeText(ApplicationContext, "activity :" + e, ToastLength.Long).Show(); } mUploadMessage.OnReceiveValue(result); mUploadMessage = null; } }
protected bool ChooseFile(IValueCallback filePathCallback, Intent intent, string title) { if (_activity == null) { return(false); } void callback(Result resultCode, Intent intentData) { if (filePathCallback == null) { return; } var result = ParseResult(resultCode, intentData); filePathCallback.OnReceiveValue(result); } _requestCodes ??= new List <int>(); var newRequestCode = ActivityResultCallbackRegistryHelper.RegisterActivityResultCallback(callback); _requestCodes.Add(newRequestCode); #pragma warning disable CA2000 // Dispose objects before losing scope _activity.StartActivityForResult(Intent.CreateChooser(intent, title), newRequestCode); #pragma warning restore CA2000 // Dispose objects before losing scope return(true); }
protected bool ChooseFile(IValueCallback filePathCallback, Intent intent, string title) { if (_activity == null) { return(false); } Action <Result, Intent> callback = (resultCode, intentData) => { if (filePathCallback == null) { return; } Java.Lang.Object result = ParseResult(resultCode, intentData); filePathCallback.OnReceiveValue(result); }; _requestCodes = _requestCodes ?? new List <int>(); int newRequestCode = ActivityResultCallbackRegistry.RegisterActivityResultCallback(callback); _requestCodes.Add(newRequestCode); _activity.StartActivityForResult(Intent.CreateChooser(intent, title), newRequestCode); return(true); }
public async void ChooseFile(IValueCallback filePathCallback, Intent intent) { GetReadPermission(); while (ReadExternalStorageAccess == null) { await Task.Delay(100); } if (ReadExternalStorageAccess == false) { return; } // make sure there is no existing message if (UploadMessage != null) { UploadMessage.OnReceiveValue(null); UploadMessage = null; } UploadMessage = filePathCallback; try { StartActivityForResult(intent, FileChooserCode); } catch (ActivityNotFoundException e) { UploadMessage = null; Toast.MakeText(this, "Cannot open file chooser", ToastLength.Long).Show(); } }
protected override void OnActivityResult(int requestCode, Result resultCode, Intent resultData) { if (requestCode == TLExtensionWebChromeClient.REQUEST_IMAGE_CODE) { if (resultCode == Result.Ok) { intentCallback.OnReceiveValue(new Android.Net.Uri[] { resultData.Data }); intentCallback = null; } else if (resultCode == Result.Canceled) { intentCallback.OnReceiveValue(null); intentCallback = null; } } }
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"); } }
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data) { if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop) { if (requestCode != FILECHOOSER_RESULTCODE && mUploadMessage == null) { base.OnActivityResult(requestCode, resultCode, data); return; } Uri[] results = null; if (resultCode == Result.Ok) { results = data == null || resultCode != Result.Ok ? null : new Android.Net.Uri[] { data.Data }; if (data == null) { if (mCameraPhotoPath != null) { results = new Uri[] { Uri.Parse(mCameraPhotoPath) }; } } } mUploadMessage.OnReceiveValue(results); mUploadMessage = null; } }
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)); }
protected override void OnActivityResult(int requestCode, Result resultCode, Intent intent) { if (requestCode == FILECHOOSER_RESULTCODE) { if (null == mUploadMessage) { return; } Java.Lang.Object result = intent == null || resultCode != Result.Ok ? null : intent.Data; mUploadMessage.OnReceiveValue(result); mUploadMessage = 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; } } }
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data) { base.OnActivityResult(requestCode, resultCode, data); if (requestCode == FilechooserResultcode) { if (mUploadMessage == null) { return; } var result = data == null || resultCode != Result.Ok ? null : data.Data; SetHtml(result.ToString()); mUploadMessage.OnReceiveValue(result); mUploadMessage = null; } }
protected override void OnActivityResult(int requestCode, Result resultCode, Android.Content.Intent data) { if (requestCode == FILECHOOSER_RESULTCODE) { if (null == UploadMessage) { return; } Java.Lang.Object result = data == null ? mCapturedImageURI : data.Data; UploadMessage.OnReceiveValue(new Android.Net.Uri[] { (Android.Net.Uri)result }); UploadMessage = null; } else { base.OnActivityResult(requestCode, resultCode, data); } }
/// <summary> /// Handle result from file chooser (input type=file in webView) /// </summary> /// <param name="requestCode"></param> /// <param name="resultCode"></param> /// <param name="data"></param> protected override void OnActivityResult(int requestCode, [GeneratedEnum] Result resultCode, Intent data) { if (requestCode == FILECHOOSER_RESULTCODE) { if (null == mUploadMessage) { return; } Android.Net.Uri[] result = data == null || resultCode != Result.Ok ? null : new Android.Net.Uri[] { data.Data }; try { mUploadMessage.OnReceiveValue(result); } catch (Exception e) { } mUploadMessage = null; } base.OnActivityResult(requestCode, resultCode, data); }
private void OnActivityResult(int requestCode, Result resultCode, Intent data) { if (data != null) { if (requestCode == FILECHOOSER_RESULTCODE) { if (null == mUploadMessage || data == null) { return; } Java.Lang.Object result = data == null || resultCode != Result.Ok ? null : data.Data; mUploadMessage.OnReceiveValue(result); mUploadMessage = null; } } }
protected override void OnActivityResult(int requestCode, Result resultCode, Intent intent) { // Handles the response from the FileChooser if (requestCode == FILECHOOSER_RESULTCODE) { if (null == UploadMessage) { return; } Java.Lang.Object result = intent == null || resultCode != Result.Ok ? null : intent.Data; UploadMessage.OnReceiveValue((result == null) ? null : new Android.Net.Uri[] { (Android.Net.Uri)result }); UploadMessage = null; } else { base.OnActivityResult(requestCode, resultCode, intent); } }
protected bool ChooseFile(IValueCallback filePathCallback, Intent intent, string title) { Action<Result, Intent> callback = (resultCode, intentData) => { if (filePathCallback == null) return; Object result = ParseResult(resultCode, intentData); filePathCallback.OnReceiveValue(result); }; _requestCodes = _requestCodes ?? new List<int>(); int newRequestCode = _context.RegisterActivityResultCallback(callback); _requestCodes.Add(newRequestCode); _context.StartActivityForResult(Intent.CreateChooser(intent, title), newRequestCode); return true; }
protected override void OnActivityResult(int requestCode, Result resultCode, Intent intent) { if (this._resultCallbackValue != null) { this._resultCallbackValue(requestCode, resultCode, intent); this._resultCallbackValue = null; } if (requestCode == FILE_CHOOSER_RESULT_CODE) { if (null == _mUploadMessage) { return; } Java.Lang.Object result = intent == null || resultCode != Result.Ok ? null : intent.Data; _mUploadMessage.OnReceiveValue(result); _mUploadMessage = null; } }
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); } }
private void OnActivityResult(int requestCode, Result resultCode, Intent data) { if (requestCode == FILECHOOSER_RESULTCODE) { if (null == mUploadMessage) { return; } mUploadMessage.OnReceiveValue(WebChromeClient.FileChooserParams.ParseResult((int)resultCode, data)); mUploadMessage = null; } else if (requestCode == IMAGE_CHOOSER_RESULTCODE) { if (null == mUploadMessage) { return; } try { Intent editIntent = new Intent(Intent.ActionEdit); var appActivity = context as MainActivity; string filePath = ""; var uri = data.Data; if (uri != null && "content".Equals(uri.Scheme)) { filePath = GetPathToImage(uri); } else { filePath = uri.Path; } _file = new File(filePath); editIntent.SetDataAndType(Android.Net.Uri.FromFile(_file), "image/*"); editIntent.SetFlags(ActivityFlags.GrantReadUriPermission); appActivity.StartActivity(Intent.CreateChooser(editIntent, AppResources.ChoisissezEditeurImage), IMAGE_EDITOR_RESULTCODE, OnActivityResult); } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e.Message); mUploadMessage.OnReceiveValue(null); } } else if (requestCode == CAMERA_RESULTCODE && resultCode == Result.Ok) { if (null == mUploadMessage) { return; } Intent editIntent = new Intent(Intent.ActionEdit); editIntent.SetDataAndType(Android.Net.Uri.FromFile(_file), "image/*"); editIntent.SetFlags(ActivityFlags.GrantReadUriPermission); var appActivity = context as MainActivity; appActivity.StartActivity(Intent.CreateChooser(editIntent, AppResources.ChoisissezEditeurImage), IMAGE_EDITOR_RESULTCODE, OnActivityResult); } else if (requestCode == IMAGE_EDITOR_RESULTCODE) { if ((!App.WifiOnlyEnabled || App.NetworkManager.GetNetworkState() == NetworkState.ReachableViaWiFiNetwork) && App.NetworkManager.GetHostServerState() == NetworkState.Reachable) { var result = new List <Android.Net.Uri>(); var contentUri = Android.Net.Uri.FromFile(_file); result.Add(contentUri); mUploadMessage.OnReceiveValue(result.ToArray()); mUploadMessage = null; } else { string title = ""; string message = ""; if (App.NetworkManager.GetHostServerState() == NetworkState.NotReachable) { title = AppResources.Alerte_ImageUploadHoteInacessibleTitle; message = AppResources.Alerte_ImageUploadHoteInacessibleMessage; } else if (App.WifiOnlyEnabled) { title = AppResources.Alerte_ImageUploadPasDeWifiTitle; message = AppResources.Alerte_ImageUploadPasDeWifiMessage; } App.NotificationManager.DisplayAlert(message, title, "OK", () => { }); Task.Run(async() => { if (!_file.Exists()) { System.Diagnostics.Debug.WriteLine("L'image " + _file.Name + " n'existe pas !!!"); } var iu = new ImageUpload() { FilePath = _file.Path, FileName = _file.Name, Field = FileChooserPheidiParams["FIELD"], QueryFieldValue = FileChooserPheidiParams["QUERYFIELDVALUE"], ServerNoseq = App.CurrentServer.Noseq, User = App.UserNoseq }; await DatabaseHelper.Database.SaveItemAsync(iu); }); mUploadMessage.OnReceiveValue(null); } } else { mUploadMessage.OnReceiveValue(null); } }