3

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.

Sylvain
  • 273
  • 2
  • 11

4 Answers4

15

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)));
Sylvain
  • 273
  • 2
  • 11
  • good info. Only is anyone aware how to further dig down into this "App info" menu? Id like to get into the "Permissions" menu, and if at all possible. Further select items in its listing – axa Dec 02 '22 at 16:29
10
Xamarin.Essentials.AppInfo.ShowSettingsUI(); 

seems to work.

Machavity
  • 30,841
  • 27
  • 92
  • 100
Wouter Klopper
  • 101
  • 1
  • 3
3

Using Xamarin through Visual Studio and C#, I switched to Application.Context.PackageName too.

I kept finding Java examples using BuildConfig.ApplicationId, but in C#, that caused me to run into your same problems. Our goals are different, but I wanted to affirm that your syntax got me one step further towards mine.

using Android.App;
using Android.Net;
...
StartActivity(new Intent(
    Android.Provider.Settings.ActionApplicationDetailsSettings, 
    Uri.Parse("package:" + Application.Context.PackageName)));
Mikish
  • 31
  • 6
1

Using @Sylvain and @Mikish answer,

I got an Exception:

Android.Util.AndroidRuntimeException: 'Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag.

Hence slightly modifying the answer:

public void OpenSettings()
{
    Intent intent = new Intent(
                    Android.Provider.Settings.ActionApplicationDetailsSettings,
                    Android.Net.Uri.Parse("package:" + Application.Context.PackageName));
    intent.AddFlags(ActivityFlags.NewTask);

    Application.Context.StartActivity(intent);
}
Junaid Pathan
  • 3,850
  • 1
  • 25
  • 47