public static IAsyncOperation <LaunchQuerySupportStatus> QueryUriSupportAsync( Uri uri, LaunchQuerySupportType launchQuerySupportType) { if (uri == null) { // counterintuitively, UWP throws plain Exception with HRESULT when passed in Uri is null throw new ArgumentNullException(nameof(uri)); } // this method may run on the background thread on UWP #if !__WASM__ if (CoreDispatcher.Main.HasThreadAccess) #else if (true) #endif { return(QueryUriSupportPlatformAsync(uri, launchQuerySupportType).AsAsyncOperation()); } else { return(CoreDispatcher.Main.RunWithResultAsync( priority: CoreDispatcherPriority.Normal, task: async() => await QueryUriSupportPlatformAsync(uri, launchQuerySupportType) ).AsAsyncOperation()); } }
public static Task <LaunchQuerySupportStatus> QueryUriSupportPlatformAsync( Uri uri, LaunchQuerySupportType launchQuerySupportType) { if (Uno.UI.ContextHelper.Current == null) { throw new InvalidOperationException( "LaunchUriAsync was called too early in application lifetime. " + "App context needs to be initialized"); } bool canOpenUri; if (!IsSpecialUri(uri)) { var androidUri = Android.Net.Uri.Parse(uri.OriginalString); var intent = new Intent(Intent.ActionView, androidUri); var manager = Uno.UI.ContextHelper.Current.PackageManager; var supportedResolvedInfos = manager.QueryIntentActivities( intent, PackageInfoFlags.MatchDefaultOnly); canOpenUri = supportedResolvedInfos.Any(); } else { canOpenUri = CanHandleSpecialUri(uri); } var supportStatus = canOpenUri ? LaunchQuerySupportStatus.Available : LaunchQuerySupportStatus.NotSupported; return(Task.FromResult(supportStatus)); }
public static IAsyncOperation <LaunchQuerySupportStatus> QueryUriSupportAsync( Uri uri, LaunchQuerySupportType launchQuerySupportType) { #if __IOS__ var canOpenUri = UIApplication.SharedApplication.CanOpenUrl( new AppleUrl(uri.OriginalString)); #elif __ANDROID__ var androidUri = Android.Net.Uri.Parse(uri.OriginalString); var intent = new Intent(Intent.ActionView, androidUri); if (Uno.UI.ContextHelper.Current == null) { throw new InvalidOperationException( "LaunchUriAsync was called too early in application lifetime. " + "App context needs to be initialized"); } var manager = Uno.UI.ContextHelper.Current.PackageManager; var supportedResolvedInfos = manager.QueryIntentActivities( intent, PackageInfoFlags.MatchDefaultOnly); var canOpenUri = supportedResolvedInfos.Any(); #endif var supportStatus = canOpenUri ? LaunchQuerySupportStatus.Available : LaunchQuerySupportStatus.NotSupported; return(Task.FromResult(supportStatus).AsAsyncOperation()); }
public Task <LaunchQuerySupportStatus> QueryUriSupportAsync(Uri uri, LaunchQuerySupportType launchQuerySupportType) { return(Task.Run(() => { bool?canOpenUri = null; try { // Easiest way: canOpenUri = CheckXdgSettings(uri); } catch (Exception exception) { // Failure here does not affect the the query. if (typeof(LauncherExtension).Log().IsEnabled(LogLevel.Error)) { typeof(LauncherExtension).Log().Error($"Failed to invoke xdg-settings", exception); } } // Guaranteed to work on all Linux Gtk platforms. canOpenUri ??= CheckMimeTypeAssociations(uri); return canOpenUri.Value ? LaunchQuerySupportStatus.Available : LaunchQuerySupportStatus.NotSupported; })); }
public static Task <LaunchQuerySupportStatus> QueryUriSupportPlatformAsync( Uri uri, LaunchQuerySupportType launchQuerySupportType) { bool canOpenUri; if (!IsSpecialUri(uri)) { #if __IOS__ canOpenUri = UIApplication.SharedApplication.CanOpenUrl( new AppleUrl(uri.OriginalString)); #else canOpenUri = NSWorkspace.SharedWorkspace.UrlForApplication(new NSUrl(uri.AbsoluteUri)) != null; #endif } else { canOpenUri = CanHandleSpecialUri(uri); } var supportStatus = canOpenUri ? LaunchQuerySupportStatus.Available : LaunchQuerySupportStatus.NotSupported; return(Task.FromResult(supportStatus)); }
public Task <LaunchQuerySupportStatus> QueryUriSupportAsync(Uri uri, LaunchQuerySupportType launchQuerySupportType) { var canOpenUri = CheckRegistry(RegistryHive.CurrentUser, uri) || CheckRegistry(RegistryHive.LocalMachine, uri); var supportStatus = canOpenUri ? LaunchQuerySupportStatus.Available : LaunchQuerySupportStatus.NotSupported; return(Task.FromResult(supportStatus)); }
/// <summary> /// Asynchronously query whether an app can be activated for the specified URI and launch type. /// </summary> /// <param name="uri">The URI.</param> /// <param name="launchQuerySupportType">The type of launch for which to query support.</param> /// <returns>Returns true if the default app for the URI scheme was launched; false otherwise.</returns> /// <remarks> /// <para/><list type="table"> /// <listheader><term>Platform</term><description>Version supported</description></listheader> /// <item><term>iOS</term><description>iOS 9.0 and later</description></item> /// <item><term>tvOS</term><description>tvOS 9.0 and later</description></item> /// <item><term>Windows UWP</term><description>Windows 10</description></item> /// <item><term>Windows Store</term><description>-</description></item> /// <item><term>Windows Phone Store</term><description>-</description></item> /// <item><term>Windows Phone Silverlight</term><description>-</description></item> /// <item><term>Windows (Desktop Apps)</term><description>Windows 7 or later</description></item></list> /// </remarks> public static Task <LaunchQuerySupportStatus> QueryUriSupportAsync(Uri uri, LaunchQuerySupportType launchQuerySupportType) { #if __ANDROID__ || __IOS__ || __TVOS__ || WIN32 return(QueryUriSupportAsyncImpl(uri, launchQuerySupportType)); #elif WINDOWS_UWP return(Task.Run <LaunchQuerySupportStatus>(async() => { var s = await Windows.System.Launcher.QueryUriSupportAsync(uri, (Windows.System.LaunchQuerySupportType)((int)launchQuerySupportType)).AsTask(); return (LaunchQuerySupportStatus)((int)s); })); #else return(Task.FromResult <LaunchQuerySupportStatus>(LaunchQuerySupportStatus.Unknown)); #endif }
public static Task <LaunchQuerySupportStatus> QueryUriSupportPlatformAsync( Uri uri, LaunchQuerySupportType launchQuerySupportType) { bool canOpenUri; if (!IsSpecialUri(uri)) { canOpenUri = UIApplication.SharedApplication.CanOpenUrl( new AppleUrl(uri.OriginalString)); } else { canOpenUri = CanHandleSpecialUri(uri); } var supportStatus = canOpenUri ? LaunchQuerySupportStatus.Available : LaunchQuerySupportStatus.NotSupported; return(Task.FromResult(supportStatus)); }
public Task <LaunchQuerySupportStatus> QueryUriSupportAsync(Uri uri, LaunchQuerySupportType launchQuerySupportType) { throw new NotImplementedException("Windows.System.Launcher.QueryUriSupportAsync is not implemented on Tizen"); }
private static Task <LaunchQuerySupportStatus> QueryUriSupportAsyncImpl(Uri uri, LaunchQuerySupportType launchQuerySupportType) { if (launchQuerySupportType == LaunchQuerySupportType.UriForResults) { return(Task.FromResult(LaunchQuerySupportStatus.AppNotInstalled)); } return(Task.FromResult(UIApplication.SharedApplication.CanOpenUrl(uri) ? LaunchQuerySupportStatus.Available : LaunchQuerySupportStatus.AppNotInstalled)); }
/// <summary> /// Asynchronously query whether an app can be activated for the specified URI and launch type. /// </summary> /// <param name="uri">The URI.</param> /// <param name="launchQuerySupportType">The type of launch for which to query support.</param> /// <returns>Returns true if the default app for the URI scheme was launched; false otherwise.</returns> /// <remarks> /// <para/><list type="table"> /// <listheader><term>Platform</term><description>Version supported</description></listheader> /// <item><term>Android</term><description>-</description></item> /// <item><term>iOS</term><description>iOS 9.0 and later</description></item> /// <item><term>tvOS</term><description>tvOS 9.0 and later</description></item> /// <item><term>Windows UWP</term><description>Windows 10</description></item> /// <item><term>Windows Store</term><description>-</description></item> /// <item><term>Windows Phone Store</term><description>-</description></item> /// <item><term>Windows Phone Silverlight</term><description>-</description></item> /// <item><term>Windows (Desktop Apps)</term><description>-</description></item></list> /// </remarks> public static Task<LaunchQuerySupportStatus> QueryUriSupportAsync(Uri uri, LaunchQuerySupportType launchQuerySupportType) { #if __IOS__ || __TVOS__ if(launchQuerySupportType == LaunchQuerySupportType.UriForResults) { return Task.FromResult<LaunchQuerySupportStatus>(LaunchQuerySupportStatus.AppNotInstalled); } return Task.FromResult<LaunchQuerySupportStatus>(UIKit.UIApplication.SharedApplication.CanOpenUrl(uri) ? LaunchQuerySupportStatus.Available : LaunchQuerySupportStatus.AppNotInstalled); #elif WINDOWS_UWP return Task.Run<LaunchQuerySupportStatus>(async () => { var s = await Windows.System.Launcher.QueryUriSupportAsync(uri, (Windows.System.LaunchQuerySupportType)((int)launchQuerySupportType)).AsTask(); return (LaunchQuerySupportStatus)((int)s); }); #else return Task.FromResult<LaunchQuerySupportStatus>(LaunchQuerySupportStatus.Unknown); #endif }
private static Task <LaunchQuerySupportStatus> QueryUriSupportAsyncImpl(Uri uri, LaunchQuerySupportType launchQuerySupportType) { return(Task.Run <LaunchQuerySupportStatus>(() => { using (Microsoft.Win32.RegistryKey rk = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(uri.Scheme)) { if (rk != null) { if (rk.GetValue("URL Protocol") != null) { return LaunchQuerySupportStatus.Available; } } } return LaunchQuerySupportStatus.NotSupported; })); }
private static Task <LaunchQuerySupportStatus> QueryUriSupportAsyncImpl(Uri uri, LaunchQuerySupportType launchQuerySupportType) { return(Task.Run <LaunchQuerySupportStatus>(() => { Android.Net.Uri u = Android.Net.Uri.Parse(uri.ToString()); Intent viewIntent = new Intent(Intent.ActionRun); viewIntent.SetData(u); try { if (viewIntent.ResolveActivity(Plugin.CurrentActivity.CrossCurrentActivity.Current.Activity.PackageManager) != null) { return LaunchQuerySupportStatus.Available; } return LaunchQuerySupportStatus.AppNotInstalled; } catch (ActivityNotFoundException) { return LaunchQuerySupportStatus.NotSupported; } })); }