Location is not getting in samsung phone if GPS is disabled

后端 未结 1 1331
野的像风
野的像风 2021-01-24 19:36

I use samsung phone to get location through LocationManager API, i\'m unable to get location if GPS is disabled, through network provider i\'m unable to get the location.

<
相关标签:
1条回答
  • 2021-01-24 19:54

    This behavior is unique to Samsung Phones. HTC you wont face this issue.

    You have to kick start locationManager, since by default it looks into the google maps cache and does not care about how stale that cache is for the current location information. Do this, launch your application, form a different gps location and notice that it still shows the old location. Now launch google maps, and relaunch your app, your location would have changed. To programmatically kick start your app for "current location" run the following code before you call getLastKnownLocation

    YOUR_APPLICATION_CONTEXT.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) {
        }
    });
    
    0 讨论(0)
提交回复
热议问题