获取'提供商未启用|调用'tracker.startListening();'时的ProviderError {provider ='network'}'即使启用WiFi也是如此

时间:2016-12-18 06:32:30

标签: android android-location locationmanager

我正在使用this库并尝试检索当前位置坐标,如下所示:

document.write(localStorage['content']);

但是,我收到了这个错误:

settings =
                new TrackerSettings()
                        .setUseGPS(false)
                        .setUseNetwork(true)
                        .setUsePassive(true)
                        .setTimeBetweenUpdates(30 * 60 * 1000);

        tracker = new LocationTracker(getBaseContext(), settings) {
            @Override
            public void onLocationFound(Location location) {
                // Do some stuff
                currentLatDouble = location.getLatitude();
                currentLngDouble = location.getLongitude();
            }

            @Override
            public void onTimeout() {

            }
        };
        tracker.startListening();

WiFi不是网络提供商,还是我需要编写一些与W/LocationTracker: Provider (network) fr.quentinklein.slt.ProviderError: Provider is not enabled | ProviderError{provider='network'} 相关的代码?

请告诉我这里有什么问题。

1 个答案:

答案 0 :(得分:0)

在清单文件

中添加了以下权限
<uses-permission android:name="android.permission.INTERNET" />
Allows applications to open network sockets.
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
Allows an app to access approximate location.
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
Allows an app to access precise location.
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Allows applications to access information about networks.
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
Allows applications to access information about Wi-Fi networks.

此外

<uses-feature
    android:name="android.hardware.location.network"
    android:required="false" />
<uses-feature
    android:name="android.hardware.location.gps"
    android:required="false" />