LocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER) is not reliable, why?

前端 未结 4 1295
孤城傲影
孤城傲影 2020-12-06 02:55

One user of my app reported that app tells network for location is off even he did turn it on. He sent me few screen shots and they made me think;

LocationMa         


        
4条回答
  •  半阙折子戏
    2020-12-06 03:04

    Location Manager is not reliable on some phones. You may notice that if you launch google maps all of a sudden your app works. That is because Google Maps kicked the LocationManager. Which also means that there is programmatic way to kick that dude alive. So I used

    HomeScreen.getLocationManager().requestLocationUpdates(
        LocationManager.NETWORK_PROVIDER, 0, 0, new LocationListener() {
            @Override
            public void onStatusChanged(String provider, int status, Bundle extras) {
            }
            @Override
            public void onProviderEnabled(String provider) {
            }
            @Override
            public void onProviderDisabled(String provider) {
            }
            @Override
            public void onLocationChanged(final Location location) {
            }
        });
    

    After the above code, I called what ever I needed from LocationManager and it kinda worked. If not try out the new API's LocationClient. This is suppose to be much better, battery, accuracy and reliability.

提交回复
热议问题