문제

I have the following code:

SosServiceListener mlistener = new SosServiceListener(this);

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

// getting network status
boolean isNetworkEnabled = manager.
                            isProviderEnabled(LocationManager.NETWORK_PROVIDER);

String provider;
if (isNetworkEnabled) {
    provider = LocationManager.NETWORK_PROVIDER;
} else {
    provider = LocationManager.GPS_PROVIDER;
}
manager.requestSingleUpdate(provider, mlistener, null);
manager.getLastKnownLocation(provider);

but the SosServiceListener is never called :( any idea why?

도움이 되었습니까?

해결책

String provider;
if (isNetworkEnabled) {
    provider = LocationManager.NETWORK_PROVIDER;
} else {
    provider = LocationManager.GPS_PROVIDER;
}

is GPS enabled on the device, with Satellite option set in Security section of mobile settings? because you are assuming that GPS_PROVIDER is enabled, just because NETWORK_PROVIDER is disabled? which is not accurate ...

also manager.getLastKnownLocation(provider); will return Location object directly and will not result a call to callback methods in the listenet...

so you need to use either one of them...

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top