Xamarin Forms/Xamarin Android 打开位置设置

问题描述 投票:0回答:1

这是新事物吗?我记得能够打开位置设置,将我带到应用程序特定页面? 有一个确切的问题可用:How to open location settings in android using xamarin

这种方法不再有效。这是代码:

try
            {
                CrossCurrentActivity.Current.Activity.StartActivity(new Intent(
                    Android.Provider.Settings.ActionLocationSourceSettings,
                    Android.Net.Uri.Parse("package:"+ Android.App.Application.Context.PackageName)));

            }
            catch (Exception e)
            {
                OpenAppSettings();
            }

不管怎样这总是会抛出错误:

android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.settings.LOCATION_SOURCE_SETTINGS dat=package: }
    at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:2200)
    at android.app.Instrumentation.execStartActivity(Instrumentation.java:1839)
    at android.app.Activity.startActivityForResult(Activity.java:5471)
    at androidx.activity.ComponentActivity.startActivityForResult(ComponentActivity.java:647)
    at android.app.Activity.startActivityForResult(Activity.java:5429)
    at androidx.activity.ComponentActivity.startActivityForResult(ComponentActivity.java:628)
    at android.app.Activity.startActivity(Activity.java:5927)
    at android.app.Activity.startActivity(Activity.java:5894)
    at androidx.appcompat.app.AlertDialog_IDialogInterfaceOnClickListenerImplementor.n_onClick(Native Method)
    at androidx.appcompat.app.AlertDialog_IDialogInterfaceOnClickListenerImplementor.onClick(AlertDialog_IDialogInterfaceOnClickListenerImplementor.java:31)
    at androidx.appcompat.app.AlertController$ButtonHandler.handleMessage(AlertController.java:167)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loopOnce(Looper.java:201)
    at android.os.Looper.loop(Looper.java:288)
    at android.app.ActivityThread.main(ActivityThread.java:7872)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)

还有, 我从 google accompanist 包中找到了这个示例代码,它似乎可以打开它,但我找不到该包专门用于打开页面的功能:

bgLocationPermissionState.launchPermissionRequest()

有什么想法吗?

android xamarin.forms xamarin.android
1个回答
0
投票

我可以在我的项目中重现该问题。但我可以使用以下代码打开位置设置:

var intent = new Android.Content.Intent(Android.Provider.Settings.ActionLocationSourceSettings);
intent.SetFlags(ActivityFlags.NewTask);
Android.App.Application.Context.StartActivity(intent);

但我可以使用以下代码打开应用程序的详细信息设置:

var intent = new Android.Content.Intent(Android.Provider.Settings.ActionApplicationDetailsSettings,
    Android.Net.Uri.Parse("package:"+ Android.App.Application.Context.PackageName));
intent.SetFlags(ActivityFlags.NewTask);
Android.App.Application.Context.StartActivity(intent);
© www.soinside.com 2019 - 2024. All rights reserved.