我正在尝试构建一个简单的 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);