How Can I Check If Gps Is Enabled Before I Try To Use It
I have the following code and it's not good because sometimes GPS takes very long How can I do the following: Check if GPS is enabled Use GPS if it is enabled otherwise use the ne
Solution 1:
There's no standard way, you have to do it on your own with the help of:
if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)){
//Do what you need if enabled...
}else{
//Do what you need if not enabled...
}
And this permission in manifest:
<uses-permissionandroid:name="android.permission.ACCESS_FINE_LOCATION"/>
As recommendation if GPS is not enabled, usually the standard specifies to popup the Location Settings Activity so the user can specifically enable it...
Hope this helps.
Regards!
Solution 2:
Just using this, you can check GPS
availability
LocationManagermlocManager= (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);;
booleanenabled= mlocManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
Solution 3:
Think you could use the code in my answer to: Location servise GPS Force closed
It gives you a callback method for GPS first fix and location changes that can be very convenient. This also makes it easy to change the implementation of GPSTracker to switch to network if GPS takes too long to get a first fix.
Post a Comment for "How Can I Check If Gps Is Enabled Before I Try To Use It"