在requestSingleUpdate()中,GPS在某些Android OS 2.3设备中没有获取位置 [英] In requestSingleUpdate(), GPS is not getting locations in some Android OS 2.3 devices

查看:427
本文介绍了在requestSingleUpdate()中,GPS在某些Android OS 2.3设备中没有获取位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我使用了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);
}

为什么requestSingleUpdate()方法与GPS提供者在某些设备上不起作用?
特别是在2.3.6操作系统版本GT-S5830型号的三星设备和MicroMax A57中无法正常工作。

解决方案

  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。如果用户没有启用位置服务,则操作系统将不会提供最佳提供商,因此提供商将返回空值。



没有什么可以做的关于这一点,这取决于用户的操作系统设置,以及他们是否选择向应用程序提供位置信息。 $ b

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


In my app, i have used requestSingleUpdate() method it's working well in all devices but in some devices 2.3 android OS version, GPS is not getting locations. Here is the code,

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);
}

Why requestSingleUpdate() method with GPS provider is not working in some devices? Specifically not working in 2.3.6 OS version GT - S5830 model Samsung device and MicroMax A57.

解决方案

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

Is asking android for the best location provider whether that be wi-fi, cell or gps. if the user doesn't have location services enabled, there will be no best provider known to the OS and so the provider will return null.

There is nothing you can do about this, it depends on the users OS settings and whether they choose make location information available to applications

--EDIT--

In your call to getBestProvider() you've asked for enabled providers only (that's the second parameter in the method call which you have set to true). If the user has disabled all providers, you will get null.

这篇关于在requestSingleUpdate()中,GPS在某些Android OS 2.3设备中没有获取位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆