我正在开发xamarin.forms应用。(仅在安卓平台上出现以下问题)
当我的应用程序启动时,它会检查我的GPS位置是否开启。
为了检查GPS位置是否开启,我使用了依赖服务。
public static bool CheckGPSConnection()
{
var gpsConnection = DependencyService.Get<IGPSConnectivity>();
return gpsConnection.CheckGPSConnection();
}
当我进入我的应用程序主页时,我放置了以下代码:
if (Device.OS == TargetPlatform.Android)
{
if (!App.CheckGPSConnection())
{
bool answer = await DisplayAlert("Alert", "Would you like to start GPS?", "Yes", "No");
if (answer)
{
Android.App.Application.Context.StartActivity(new Android.Content.Intent(Android.Provider.Settings.ActionLocationSourceSettings));
}
}
}
但是它给了我一个异常。
{Android.Util.AndroidRuntimeException:从Activity上下文之外调用startActivity()需要FLAG_ACTIVITY_NEW_TASK标志。这真的是你想要的吗?在System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() [0x0000c]中 [Users/…}
我该怎么办?
Xamarin.Forms.Forms.Context
。 - Gerald Versluis