Skip to content

Instantly share code, notes, and snippets.

@jbachelor
Created April 14, 2020 16:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbachelor/d7ff2e61941ae194c5952e6691563dff to your computer and use it in GitHub Desktop.
Save jbachelor/d7ff2e61941ae194c5952e6691563dff to your computer and use it in GitHub Desktop.
Open app settings on iOS/Android using a Dependency Service
namespace MyCoolMobileApp.Services.DependencyServices
{
public interface ISettingsAppLauncher
{
void LaunchSettingsApp(string appBundleId);
}
}
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);
}
}
}
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);
}
}
}
@VoterClopper
Copy link

Thanks!

@jbachelor
Copy link
Author

@VoterClopper
Copy link

Xamarin.Essentials.AppInfo.ShowSettingsUI(); seems to work.

@jbachelor
Copy link
Author

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