在requestSingleUpdate()中,GPS没有在某些Android OS 2.3设备中获取位置

时间:2013-08-06 14:03:38

标签: android gps

在我的应用程序中,我使用了requestSingleUpdate()方法,它在所有设备上运行良好,但在某些设备2.3 Android操作系统版本中,GPS无法获取位置。这是代码,

Intent intentp = new Intent(context, MyLocationReceiver.class);
pendingIntent = PendingIntent.getBroadcast(context, 0, intentp,PendingIntent.FLAG_UPDATE_CURRENT);
criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_COARSE);
provider = locationManager.getBestProvider(criteria, true);
if(provider != null)
{               
    locationManager.requestSingleUpdate(provider, pendingIntent);
}

为什么使用GPS提供程序的requestSingleUpdate()方法在某些设备中不起作用? 特别是在2.3.6 OS版GT-S5830型三星设备和MicroMax A57中无法使用。

2 个答案:

答案 0 :(得分:1)

criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_COARSE);
provider = locationManager.getBestProvider(criteria, true);
if(provider != null)
{               
    locationManager.requestSingleUpdate(provider, pendingIntent);
}

要求android为最佳位置提供商,无论是wi-fi,cell还是gps。如果用户没有启用位置服务,则操作系统不会知道最佳提供程序,因此提供程序将返回null。

您无能为力,这取决于用户操作系统设置以及他们是否选择将位置信息提供给应用程序

- 编辑 -

在你对getBestProvider()的调用中,你只要求启用的提供者(这是方法调用中你设置为true的第二个参数)。如果用户已禁用所有提供程序,则您将获得null。

答案 1 :(得分:1)

LocationClient优先于LocationManager retrieving the current location

它使用Google Play Services(在几乎100%的设备中都可用),它功能更强大,通常可以解决许多问题。自从我进行切换以来,我从来没有遇到任何类型的位置问题。