Locationmanager Not Working On Android Phone
Solution 1:
Maybe you are testing indoors, and can't get any GPS information.
Try to change LocationManager.GPS_PROVIDER-->LocationManager.NETWORK_PROVIDER.
Solution 2:
It could be a problem with your incorrect usage of String.format()
. Sometimes this can cause weird, device-specific issues. Try,
String lon = "" + location.getLongitude();
String lat = "" + location.getLatitude();
String num = getMyPhoneNumber();
String message = String.format(
"New Location \n Longitude: %1$s \n Latitude: %2$s \n %3$s",
lon,
lat,
num
);
Have you tried using this?
LocationManagerlm= (LocationManager)act.getSystemService(Context.LOCATION_SERVICE);
Criteriacrit=newCriteria();
crit.setAccuracy(Criteria.ACCURACY_FINE);
Stringprovider= lm.getBestProvider(crit, true);
Locationloc= lm.getLastKnownLocation(provider);
Solution 3:
i had similar issues using the locationmanager on my HTC incredible S running 4.0.4. it would simply stop firing location changes on the real device after some time. on some other devices it would work. very intermittent.
my solution was to piss off the LocationManager and use LocationClient pardiagm. http://developer.android.com/reference/com/google/android/gms/location/LocationClient.html
ever since google play services have been introduced the Locationmanager has been intermittent on my device. I cant give any other explanation as to why it occurs.
But the LocationClient works everytime plus it removes the dumb 'provider' notion from location management.
Post a Comment for "Locationmanager Not Working On Android Phone"