Created
April 14, 2020 16:38
-
-
Save jbachelor/d7ff2e61941ae194c5952e6691563dff to your computer and use it in GitHub Desktop.
Open app settings on iOS/Android using a Dependency Service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace MyCoolMobileApp.Services.DependencyServices | |
{ | |
public interface ISettingsAppLauncher | |
{ | |
void LaunchSettingsApp(string appBundleId); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Diagnostics; | |
using Android.Content; | |
using Plugin.CurrentActivity; // https://github.com/jamesmontemagno/CurrentActivityPlugin | |
using MyCoolMobileApp.Droid.Services.DependencyServices; | |
using MyCoolMobileApp.Services.DependencyServices; | |
using Xamarin.Forms; | |
[assembly: Dependency(typeof(SettingsAppLauncher_Android))] | |
namespace MyCoolMobileApp.Droid.Services.DependencyServices | |
{ | |
public class SettingsAppLauncher_Android : ISettingsAppLauncher | |
{ | |
public void LaunchSettingsApp(string appBundleId) | |
{ | |
Debug.WriteLine($"**** {this.GetType().Name}.{nameof(LaunchSettingsApp)}"); | |
var intent = new Intent(Android.Provider.Settings.ActionApplicationDetailsSettings); | |
intent.AddFlags(ActivityFlags.NewTask); | |
var uri = Android.Net.Uri.FromParts("package", appBundleId, null); | |
intent.SetData(uri); | |
CrossCurrentActivity.Current.AppContext.StartActivity(intent); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Diagnostics; | |
using Foundation; | |
using MyCoolMobileApp.iOS.Services.DependencyServices; | |
using MyCoolMobileApp.Services.DependencyServices; | |
using UIKit; | |
using Xamarin.Forms; | |
[assembly: Dependency(typeof(SettingsAppLauncher_iOS))] | |
namespace MyCoolMobileApp.iOS.Services.DependencyServices | |
{ | |
public class SettingsAppLauncher_iOS : ISettingsAppLauncher | |
{ | |
public void LaunchSettingsApp(string appBundleId) | |
{ | |
Debug.WriteLine($"**** {this.GetType().Name}.{nameof(LaunchSettingsApp)}"); | |
var url = new NSUrl($"app-settings:{appBundleId}"); | |
UIApplication.SharedApplication.OpenUrl(url); | |
} | |
} | |
} |
Xamarin.Essentials.AppInfo.ShowSettingsUI(); seems to work.
Awesome, @VoterClopper... I don't think that was working back when I wrote this up, but that will make things massively simpler!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks!