Android模拟位置提供程序未从LocationManager清除

时间:2011-10-21 08:53:01

标签: android gps locationmanager

我遇到了模拟位置提供商的问题。我有一个需要获得准确有效位置的应用程序,我不希望用户能够欺骗它们。所以我检查了模拟位置启用设置,它工作正常。

然而,位置提供商存在问题。如果启用模拟位置,使用gps faker应用程序设置位置,然后禁用模拟位置和所有其他位置提供程序,则位置管理器仍具有对模拟位置提供程序的引用。因此,虽然禁用了模拟位置,但位置管理器告诉我gps已启用,并提供模拟的位置数据。

我知道您可以从位置管理器中清除测试提供程序,但必须启用模拟位置才能执行此操作

有人遇到过这种情况,或者有过解决方法吗?

2 个答案:

答案 0 :(得分:3)

想想我是否找到了一种准确读数的方法,无论GPS /网络提供商是否启用:

ContentResolver contentResolver = context.getContentResolver();
boolean gpsEnabled = Settings.Secure.isLocationProviderEnabled(contentResolver, LocationManager.GPS_PROVIDER);
boolean networkEnabled = Settings.Secure.isLocationProviderEnabled(contentResolver, LocationManager.NETWORK_PROVIDER);

答案 1 :(得分:1)

你确定你打过电话:

  • removeUpdates()
  • removeTestProvider()
  • setTestProviderEnabled() with false
  • clearTestProviderEnabled()

看看LocationManagerTest如何做到这一点。

// disable mocking. 
Settings.Secure.putString(getContentResolver(),
       Settings.Secure.ALLOW_MOCK_LOCATION, "0");