Search code examples
androidandroid-activityxamarin

I'd like to open the app settings page from a Xamarin Android app


I need to open the app settings page for my Xamarin Android app.

Using Java, it seems that the correct way to do it is:

startActivity(new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
              Uri.parse("package:" + BuildConfig.APPLICATION_ID)));

So, using C#, I tried:

StartActivity(new Intent(Android.Provider.Settings.ActionApplicationDetailsSettings,
              Android.Net.Uri.Parse("package:" + BuildConfig.ApplicationId)));

This does nothing... I tried without the Uri parameter, and in that case I get an exception:

Android.Content.ActivityNotFoundException: No Activity found to handle Intent { act=android.settings.APPLICATION_DETAILS_SETTINGS }

I also tried

StartActivityForResult(
    new Intent(Android.Provider.Settings.ActionApplicationDetailsSettings), 0);

Same exception...

Any idea?

Thanks.


Solution

  • I finally found the issue!

    In

    StartActivity(new Intent(Android.Provider.Settings.ActionApplicationDetailsSettings,
              Android.Net.Uri.Parse("package:" + BuildConfig.ApplicationId)));
    

    It's the

    BuildConfig.ApplicationId
    

    that doesn't work...

    The correct call (or at least the one that worked for me) using Xamarin is then

    StartActivity(new Intent(
        Android.Provider.Settings.ActionApplicationDetailsSettings,
        Android.Net.Uri.Parse("package:"+ Android.App.Application.Context.PackageName)));