I am working on an app for Android and iOS using Xamarin.Forms along with Xamarin.Essentials. I'd like to be able to provide a button in my app that would take the user to the device's 'Settings' app, then into the specific settings page for this app I'm working on.
Previously, this has been done using a dependency service to call into platform-specific code. I believe one can accomplish this much more simply, and without any platform-specific code using the Xamarin.Essentials Launcher (Microsoft documentation here). I have figured out how to do this on iOS:
bool didOpenUri = await Xamarin.Essentials.Launcher.TryOpenAsync("app-settings:com.yourCompany.yourApp");
However, I have not been able to discover how to do this on Android. If anything is unclear, please let me know. Otherwise, any assistance is appreciated... Thanks very much!
As I know, there are no URLs for Android Settings. The Launcher do not support it.
But, the Settings class provides action strings for the Settings app.
Settings Class: https://learn.microsoft.com/en-us/dotnet/api/android.provider.settings?view=xamarin-android-sdk-9
You could do this in Android:
StartActivity(new Intent(Settings.ActionSettings));
And use Dependency service to do that in Xamarin.Forms.
Dependency service: https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/dependency-service/introduction
Updated:
In Xamarin.Forms:
Create a interface:
public interface IStartSetttings
{
void StartSettings();
}
Implementation of Android:
[assembly: Dependency(typeof(StartSettings_Implementation))]
namespace XamarinDemo.Droid.DependencyService_Implementation
{
class StartSettings_Implementation : MainActivity, IStartSetttings
{
public void StartSettings()
{
var intent = new Intent(Settings.ActionSettings);
Forms.Context.StartActivity(intent);
}
}
}
Usage in Xamarin.Forms:
DependencyService.Get<IStartSetttings>().StartSettings();
Screenshot: