【问题标题】:Gps is not working after restart my mobile重新启动我的手机后GPS无法正常工作
【发布时间】:2013-01-31 07:26:43
【问题描述】:

我正在开发一个应用程序,因为我需要找到当前位置值。为此,我以编程方式启用了 gps。现在,我关闭并打开了我的手机。现在,我无法获取当前位置值,但我设备的 gps 已打开。

我在(motorola 2.3.3、htc 2.3.4 和 nexus 4.2.1)中发现了这个问题

我使用了以下代码。

String provider = Settings.Secure.getString(getContentResolver(),Settings.Secure.LOCATION_PROVIDERS_ALLOWED);

    if(!provider.contains("gps")){ //if gps is disabled
        final Intent poke = new Intent();
        poke.setClassName("com.android.settings", "com.android.settings.widget.SettingsAppWidgetProvider"); 
        poke.addCategory(Intent.CATEGORY_ALTERNATIVE);
        poke.setData(Uri.parse("3")); 
        sendBroadcast(poke);

locationManager = (LocationManager) getSystemService  (Context.LOCATION_SERVICE);

Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
List<String> provider = locationManager.getProviders(true);
Location location = null;
for (int i=provider.size()-1; i>=0; i--) 
{
       location = locationManager.getLastKnownLocation(provider.get(i));
       if (location != null) break;

if (location != null) 
   {
      String latitude=String.valueOf(location.getLatitude());
      String longitude=String.valueOf(location.getLongitude());    
   }

【问题讨论】:

    标签: android gps location


    【解决方案1】:

    打开 GPS 后,您必须调用 requestLocationUpdate 以便 GPS 开始感应。 希望这可能会有所帮助。

    【讨论】:

      猜你喜欢
      • 2014-03-25
      • 1970-01-01
      • 1970-01-01
      • 2019-09-16
      • 2021-09-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多