【问题标题】:java.lang.IllegalArgumentException: provider doesn't exist: gpsjava.lang.IllegalArgumentException:提供者不存在:gps
【发布时间】:2016-06-29 03:56:07
【问题描述】:

我正在使用 GPS 获取用户位置,在 Android 5.0 的 Samsung Galaxy S5(klte) 中显示类似 java.lang.IllegalArgumentException: provider doesn't exist: gps 的错误,但设备有 GPS。可以告诉什么错误确切地表示没有 GPS 或无法访问 GPS。

谁能知道帮我解决这个问题。

错误日志

Caused by: java.lang.IllegalArgumentException: provider doesn't exist: gps
at android.os.Parcel.readException(Parcel.java:1544)
at android.os.Parcel.readException(Parcel.java:1493)
at android.location.ILocationManager$Stub$Proxy.requestLocationUpdates(ILocationManager.java:584)
at android.location.LocationManager.requestLocationUpdates(LocationManager.java:867)
at android.location.LocationManager.requestLocationUpdates(LocationManager.java:459)
at melbourne.webdesign.karmaridedriver.Driver_location_update.onStartCommand(Driver_location_update.java:62)
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3259)
... 9 more

Driver_location_update.java:62

表示线以下

locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 4000, 0, listener);

【问题讨论】:

  • 哇,没有人以任何令人满意的方式回答这个问题。

标签: android gps android-location


【解决方案1】:

我在我的应用程序中遇到了同样的事情。在查看崩溃日志时,我发现它发生的设备是 RCA Voyager 16GB。查看该设备的规格,我发现它没有 GPS。因此,您的问题是,GPS 在该设备的其他应用程序中是否正常工作?

就我而言,我实际上无法重现该问题,因为我没有没有 GPS 的设备,但我最好的办法是尝试保护我从该提供商处打开位置更新。

if (lm.isProviderEnabled(LocationManager.GPS_PROVIDER) ) {
    lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, Constants.LOCATION_UPDATE_INTERVAL, 0, this);
}

我认为这里真正的答案是转到 FusedLocationProviderApi,然后这成为 api 的问题。但有时我更喜欢稍微微调代码以使其工作,而不是拿出斧头开始黑客攻击。

【讨论】:

  • 我的设备有 GPS,但该代码给出错误。无论如何,您最好使用 FusedLocationProviderApi。我使用 FusedLocationProviderApi 来解决我的问题。
【解决方案2】:

试试这个 -

private Location getMyLocation() {

        LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
        Location myLocation = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);


        // if Location wasn't found
        if (myLocation == null) {
            Criteria criteria = new Criteria();
            criteria.setAccuracy(Criteria.ACCURACY_COARSE);

            String provider = lm.getBestProvider(criteria, true);
            // Use the provider to get the last known location
            myLocation = lm.getLastKnownLocation(provider);
            double lat1 = myLocation.getLatitude();
            double lng1 = myLocation.getLongitude();


        }

        return myLocation;
    }

在 onCreate() 中调用此方法并为该活动使用 OnMyLocationChangeListener。它对我很有用:)

注意:不推荐使用 OnMyLocationChangeListener(请查看谷歌文档)

【讨论】:

    【解决方案3】:

    某些设备上不存在网络或 GPS 提供程序,因此如果您启动相应的服务,它就不起作用。 最好使用这样的 if 语句进行检查:

    if(locationManager.getAllProviders().contains("network")) {
         locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, time, distance, this);
    }
    

    工作得很好

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-26
      • 1970-01-01
      • 1970-01-01
      • 2020-11-28
      • 2013-12-19
      • 1970-01-01
      相关资源
      最近更新 更多