Hi Everyone,
I am facing a very strange issue, When the app open it asks for the permission to access the camera and if I deny . And when i open for the camera the app crashes. Here is the snippet.
Device.BeginInvokeOnMainThread(async () => { var action = await DisplayActionSheet("Add Photo", "Cancel", null, "Choose Existing", "Take Photo"); if (action == "Choose Existing") { if (!CrossMedia.Current.IsPickPhotoSupported) { await DisplayAlert("Photos Not Supported", ":( Permission not granted to photos.", "OK"); return; } var file = await Plugin.Media.CrossMedia.Current.PickPhotoAsync(new Plugin.Media.Abstractions.PickMediaOptions { PhotoSize = Plugin.Media.Abstractions.PhotoSize.Medium, }); if (file == null) return; archieImg.Source = ImageSource.FromStream(() => { var stream = file.GetStream(); return stream; }); archieImg.IsVisible = true; imgPet.IsVisible = false; MessagingCenter.Send(new PetModel() { ImageUrl = archieImg.Source }, "Image"); asd = archieImg; } else if (action == "Take Photo") { if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported) { await DisplayAlert("No Camera", ":( No camera avaialble.", "OK"); return; } var file = await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions { PhotoSize = Plugin.Media.Abstractions.PhotoSize.Medium, Directory = "Sample", Name = "test.jpg", AllowCropping = true }); if (file == null) return; archieImg.Source = ImageSource.FromStream(() => { var stream = file.GetStream(); return stream; }); archieImg.IsVisible = true; imgPet.IsVisible = false; MessagingCenter.Send(new PetModel() { ImageUrl = archieImg.Source }, "Image"); asd = archieImg; } });
Thanks