3

Trying to open my app settings , so the user can see the permissions my app is required. cant find anything with a similar example. *

if (item.Name == "Privacy preferences")
            {
                switch (Device.RuntimePlatform)
                {
                    case Device.iOS:
                        Device.OpenUri(
                          new Uri(FORGOT WHAT TO PUT IN HERE .. APP/SETTINGS?);
                        break;
                    case Device.Android:
                        Device.OpenUri(
                          new Uri();
                        break;
                }

*

2 Answers 2

11

Fairly simple, you will have to create platform specific implementations.

The Interface

public interface ISettingsHelper
{
    void OpenAppSettings();
}

iOS

public void OpenAppSettings()
{
    var url = new NSUrl($"app-settings:{app_bundle_id}");
    UIApplication.SharedApplication.OpenUrl(url);
}

Android

public void OpenAppSettings()
{
    var intent = new Intent(Android.Provider.Settings.ActionApplicationDetailsSettings);
    intent.AddFlags(ActivityFlags.NewTask);
    var uri = Android.Net.Uri.FromParts("package", package_name, null);
    intent.SetData(uri);
    Application.Context.StartActivity(intent);
}

From Xamarin.Forms project you could simple call OpenAppSettings();.

P.S.: Please keep in mind that this solution requires tweaking if you would like it to work on older devices.

2
  • Thank you for the answer , will try it now. quick question if I dont want to deal with older devices will I just display a sort of alert ? just to be safe .
    – Pxaml
    Commented May 2, 2018 at 15:51
  • To be safe you can wrap it with try catch blocks and act accordingly. This solution is tested on Android 7.0 and iOS 11.3.
    – EvZ
    Commented May 2, 2018 at 15:53
2

Try Device.OpenUri(new Uri("app-settings:"));

If this doesn't work (I think it has a while ago), you probably have to do this in your platform specific parts and use e.g. the dependency service. For IOS then use UIApplication.SharedApplication.OpenUrl(new NSUrl("app-settings:"));

Edit: @EvZ's answer is the one with platform specific code and the abstraction, if you also need UWP you can call await Windows.System.Launcher.LaunchUriAsync(new Uri("ms-settings:privacy-location"));

1
  • your solution works good on ios but not android . I don`t know for some weird reason , I did this way back and it used to work for both platforms. I will try @EvZ solution as well . Thank you so much for the help.
    – Pxaml
    Commented May 2, 2018 at 15:48

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.