static async Task <IEnumerable <FileResult> > PlatformPickAsync(PickOptions options, bool allowMultiple = false) { Permissions.EnsureDeclared <Permissions.LaunchApp>(); await Permissions.EnsureGrantedAsync <Permissions.StorageRead>(); var tcs = new TaskCompletionSource <IEnumerable <FileResult> >(); var appControl = new AppControl(); appControl.Operation = AppControlOperations.Pick; appControl.ExtraData.Add(AppControlData.SectionMode, allowMultiple ? "multiple" : "single"); appControl.LaunchMode = AppControlLaunchMode.Single; var fileType = options?.FileTypes?.Value?.FirstOrDefault(); appControl.Mime = fileType ?? FileSystem.MimeTypes.All; var fileResults = new List <FileResult>(); AppControl.SendLaunchRequest(appControl, (request, reply, result) => { if (result == AppControlReplyResult.Succeeded) { if (reply.ExtraData.Count() > 0) { var selectedFiles = reply.ExtraData.Get <IEnumerable <string> >(AppControlData.Selected).ToList(); fileResults.AddRange(selectedFiles.Select(f => new FileResult(f))); } } tcs.TrySetResult(fileResults); }); return(await tcs.Task); }
static void PlatformShowSettingsUI() { Permissions.EnsureDeclared <Permissions.LaunchApp>(); AppControl.SendLaunchRequest(new AppControl() { Operation = AppControlOperations.Setting }); }
static void StartListeners() { Permissions.EnsureDeclared <Permissions.NetworkState>(); conectivityReceiver = new ConnectivityBroadcastReceiver(OnConnectivityChanged); #pragma warning disable CS0618 // Type or member is obsolete Platform.AppContext.RegisterReceiver(conectivityReceiver, new IntentFilter(ConnectivityManager.ConnectivityAction)); #pragma warning restore CS0618 // Type or member is obsolete }
static void PlatformPerform(HapticFeedbackType type) { Permissions.EnsureDeclared <Permissions.Vibrate>(); try { Platform.CurrentActivity?.Window?.DecorView?.PerformHapticFeedback(ConvertType(type)); } catch (Exception ex) { Debug.WriteLine($"HapticFeedback Exception: {ex.Message}"); } }
internal static Task PlatformOpenMapsAsync(Placemark placemark, MapLaunchOptions options) { Permissions.EnsureDeclared <Permissions.LaunchApp>(); var appControl = new AppControl { Operation = AppControlOperations.Pick, Uri = "geo:", }; appControl.Uri += $"0,0?q={placemark.GetEscapedAddress()}"; AppControl.SendLaunchRequest(appControl); return(Task.CompletedTask); }
internal static Task PlatformOpenMapsAsync(double latitude, double longitude, MapLaunchOptions options) { Permissions.EnsureDeclared <Permissions.LaunchApp>(); var appControl = new AppControl { Operation = AppControlOperations.View, Uri = "geo:", }; appControl.Uri += $"{latitude.ToString(CultureInfo.InvariantCulture)},{longitude.ToString(CultureInfo.InvariantCulture)}"; AppControl.SendLaunchRequest(appControl); return(Task.CompletedTask); }
static void PlatformOpen(string number) { Permissions.EnsureDeclared <Permissions.LaunchApp>(); var appControl = new AppControl { Operation = AppControlOperations.Dial, Uri = "tel:", }; if (!string.IsNullOrEmpty(number)) { appControl.Uri += number; } AppControl.SendLaunchRequest(appControl); }
static void PlatformPerform(HapticFeedbackType type) { Permissions.EnsureDeclared <Permissions.Vibrate>(); try { var feedback = new Feedback(); var pattern = ConvertType(type); if (feedback.IsSupportedPattern(FeedbackType.Vibration, pattern)) { feedback.Play(FeedbackType.Vibration, pattern); } } catch (Exception ex) { Debug.WriteLine($"HapticFeedback Exception: {ex.Message}"); } }
static async Task <IEnumerable <Location> > PlatformGetLocationsAsync(string address) { Permissions.EnsureDeclared <Permissions.Maps>(); if (string.IsNullOrWhiteSpace(Platform.MapServiceToken)) { throw new ArgumentNullException(nameof(Platform.MapServiceToken)); } var map = await Platform.GetMapServiceAsync(Platform.MapServiceToken); var request = map.CreateGeocodeRequest(address); var list = new List <Location>(); foreach (var position in await request.GetResponseAsync()) { list.Add(new Location(position.Latitude, position.Longitude)); } return(list); }
static void PlatformVibrate(TimeSpan duration) { Permissions.EnsureDeclared <Permissions.Vibrate>(); var time = (long)duration.TotalMilliseconds; #if __ANDROID_26__ if (Platform.HasApiLevelO) { Platform.Vibrator.Vibrate(VibrationEffect.CreateOneShot(time, VibrationEffect.DefaultAmplitude)); return; } #endif #pragma warning disable CS0618 // Type or member is obsolete Platform.Vibrator.Vibrate(time); #pragma warning restore CS0618 // Type or member is obsolete }
internal static Task SwitchFlashlight(bool switchOn) { Permissions.EnsureDeclared <Permissions.Flashlight>(); return(Task.Run(() => { if (!IsSupported) { throw new FeatureNotSupportedException(); } if (switchOn) { Led.Brightness = Led.MaxBrightness; } else { Led.Brightness = 0; } })); }
static Task PlatformOpenAsync(OpenFileRequest request) { if (string.IsNullOrEmpty(request.File.FullPath)) { throw new ArgumentNullException(nameof(request.File.FullPath)); } Permissions.EnsureDeclared <Permissions.LaunchApp>(); var appControl = new AppControl { Operation = AppControlOperations.View, Mime = FileSystem.MimeTypes.All, Uri = "file://" + request.File.FullPath, }; AppControl.SendLaunchRequest(appControl); return(Task.CompletedTask); }
static void StartListeners() { Permissions.EnsureDeclared <Permissions.NetworkState>(); var filter = new IntentFilter(); if (Platform.HasApiLevelN) { RegisterNetworkCallback(); filter.AddAction(Platform.EssentialsConnectivityChanged); } else { #pragma warning disable CS0618 // Type or member is obsolete filter.AddAction(ConnectivityManager.ConnectivityAction); #pragma warning restore CS0618 // Type or member is obsolete } conectivityReceiver = new ConnectivityBroadcastReceiver(OnConnectivityChanged); Platform.AppContext.RegisterReceiver(conectivityReceiver, filter); }
static Task PlatformRequestAsync(ShareMultipleFilesRequest request) { Permissions.EnsureDeclared <Permissions.LaunchApp>(); var appControl = new AppControl { Operation = AppControlOperations.Share, }; if (!string.IsNullOrEmpty(request.Title)) { appControl.ExtraData.Add(AppControlData.Title, request.Title); } foreach (var file in request.Files) { appControl.ExtraData.Add(AppControlData.Path, file.FullPath); } AppControl.SendLaunchRequest(appControl); return(Task.CompletedTask); }
static Task PlatformComposeAsync(SmsMessage message) { Permissions.EnsureDeclared <Permissions.LaunchApp>(); var appControl = new AppControl { Operation = AppControlOperations.Compose, Uri = "sms:", }; if (!string.IsNullOrEmpty(message.Body)) { appControl.ExtraData.Add(AppControlData.Text, message.Body); } if (message.Recipients.Count > 0) { appControl.Uri += string.Join(" ", message.Recipients); } AppControl.SendLaunchRequest(appControl); return(Task.CompletedTask); }
static async Task <Contact> PlatformPickContactAsync() { Permissions.EnsureDeclared <Permissions.ContactsRead>(); Permissions.EnsureDeclared <Permissions.LaunchApp>(); await Permissions.EnsureGrantedAsync <Permissions.ContactsRead>(); var tcs = new TaskCompletionSource <Contact>(); var appControl = new AppControl(); appControl.Operation = AppControlOperations.Pick; appControl.ExtraData.Add(AppControlData.SectionMode, "single"); appControl.LaunchMode = AppControlLaunchMode.Single; appControl.Mime = "application/vnd.tizen.contact"; AppControl.SendLaunchRequest(appControl, (request, reply, result) => { Contact contact = null; if (result == AppControlReplyResult.Succeeded) { var contactId = reply.ExtraData.Get <IEnumerable <string> >(AppControlData.Selected)?.FirstOrDefault(); if (int.TryParse(contactId, out var contactInt)) { var record = manager.Database.Get(TizenContact.Uri, contactInt); if (record != null) { contact = ToContact(record); } } } tcs.TrySetResult(contact); }); return(await tcs.Task); }
static Task <bool> PlatformOpenAsync(Uri uri, BrowserLaunchOptions launchMode) { if (uri == null) { throw new ArgumentNullException(nameof(uri)); } Permissions.EnsureDeclared <Permissions.LaunchApp>(); var appControl = new AppControl { Operation = AppControlOperations.View, Uri = uri.AbsoluteUri }; var hasMatches = AppControl.GetMatchedApplicationIds(appControl).Any(); if (hasMatches) { AppControl.SendLaunchRequest(appControl); } return(Task.FromResult(hasMatches)); }
static void StartListeners() { Permissions.EnsureDeclared <Permissions.NetworkState>(); ConnectionManager.ConnectionTypeChanged += OnChanged; GetProfileListAsync(); }
static void PlatformCancel() { Permissions.EnsureDeclared <Permissions.Vibrate>(); Platform.Vibrator.Cancel(); }
static void PlatformCancel() { Permissions.EnsureDeclared <Permissions.Vibrate>(); Vibrator.Vibrators.FirstOrDefault()?.Stop(); }
static void PlatformVibrate(TimeSpan duration) { Permissions.EnsureDeclared <Permissions.Vibrate>(); Vibrator.Vibrators.FirstOrDefault()?.Vibrate((int)duration.TotalMilliseconds, 100); }