0

我正在尝试构建一个简单的 Android 模拟位置提供(Android 7.0)。我正在接受Java.Lang.SecurityException...不允许执行MockLocationException。我有android.permission.ACCESS_MOCK_LOCATION清单文件。我也尝试过同样的方法Xamarin并得到了同样的错误。

Location location = new Location(LocationManager.GpsProvider);

location.Latitude = 20.0;
location.Longitude = 20.0;
location.Accuracy = 0;
location.Time = DateTime.Now.Ticks;
location.ElapsedRealtimeNanos = 100;
location.Speed = 0.0f;
location.Altitude = 1.0;
location.Bearing = 0.0f;

LocationManager locationManager = GetSystemService(LocationService) as 
LocationManager;

locationManager.AddTestProvider(LocationManager.GpsProvider, false, 
       false, false, false, false, false, false, Power.Low, 
Android.Hardware.SensorStatus.AccuracyHigh);
// getting exception on the above line

locationManager.SetTestProviderLocation(LocationManager.GpsProvider, 
           location);
locationManager.SetTestProviderEnabled(LocationManager.GpsProvider, true);
4

1 回答 1

1

您需要在设备的设置-开发人员选项设置中启用允许模拟位置,并在清单中添加 ACCESS_MOCK_LOCATION 权限。这将使您能够将模拟位置发送到您的应用程序

于 2019-04-17T10:52:10.033 回答