private async Task RefreshHandle() { if (Xamarin.Forms.Device.RuntimePlatform == Xamarin.Forms.Device.Android) { var status = await _permissions.CheckPermissionStatusAsync(Permission.Location); if (status != PermissionStatus.Granted) { var permissionResult = await _permissions.RequestPermissionsAsync(Permission.Location); if (permissionResult.First().Value != PermissionStatus.Granted) { await _userDialogs.AlertAsync("Permission denied. Not scanning."); _permissions.OpenAppSettings(); return; } } } await ScanForDevices(); IsRefreshing = false; }
private async void PrintImage() { var action = await _pageDialogService.DisplayActionSheetAsync("Pick Photo", "Cancel", null, TakePhoto, PickPhoto); if (action == null) { return; } try { if (action.Equals(TakePhoto)) { if (!_mediaService.IsCameraAvailable || !_mediaService.IsTakePhotoSupported) { await _pageDialogService.DisplayAlertAsync("No Camera", "There is no camera available", "Ok"); return; } var file = await _mediaService.TakePhotoAsync(new StoreCameraMediaOptions { Directory = "TestPrintApp", SaveToAlbum = true, CompressionQuality = 75, CustomPhotoSize = 50, PhotoSize = PhotoSize.MaxWidthHeight, MaxWidthHeight = 2000, DefaultCamera = CameraDevice.Front }); if (file != null) { // Get stream of selected image and send to service _printService.PrintPdfFile(file.GetStream()); } } else if (action.Equals(PickPhoto)) { if (!_mediaService.IsPickPhotoSupported) { await _pageDialogService.DisplayAlertAsync("No Photos", "No Photo permission", "Ok"); return; } var file = await _mediaService.PickPhotoAsync(new PickMediaOptions { PhotoSize = PhotoSize.Medium, }); if (file != null) { // Get stream of selected image and send to service _printService.PrintPdfFile(file.GetStream()); } } } catch (MediaPermissionException ex) { Debug.WriteLine(ex.ToString()); if (Device.RuntimePlatform == Device.iOS) { var result = await _pageDialogService.DisplayAlertAsync("Permission Rejected", "No permission", "Enable", "Cancel"); if (result) { _permissionService.OpenAppSettings(); } } else { await _pageDialogService.DisplayAlertAsync("Permission Rejected", "No permission", "Cancel"); } } }