setTestProviderLocation() does not trigger calling of onLocationChanged()

前端 未结 6 2102
野的像风
野的像风 2020-12-10 07:42

I\'m trying to get this bit of code to work:

Testing GPS in Android

The problem is, when I run the test, onLocationChanged() is never called:



        
6条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-10 08:26

    This is what worked for me

    locationManager.addTestProvider(mocLocationProvider, false, false,
                        false, false, true, true, true, 0, 5);
    locationManager.setTestProviderEnabled(mocLocationProvider, true);
    

    .

    Location mockLocation = new Location(mocLocationProvider); // a string
    mockLocation.setLatitude(location.getLatitude());  // double 
    mockLocation.setLongitude(location.getLongitude()); 
    mockLocation.setAltitude(location.getAltitude()); 
    mockLocation.setTime(System.currentTimeMillis()); 
    locationManager.setTestProviderLocation( mocLocationProvider, mockLocation); 
    

    .

    
    

    Also in the android phone settings make sure you have the "Allow mock locations" checkbox ticked

提交回复
热议问题