I am working on an Android 3.2+ app in Titanium. It is crucial that I am able to determine if the device has GPS enabled. According to the Titanium API reference, Ti.Geolocation.locationServicesEnabled will always return true on Android 2.2+, because of a new "passive" location provider. Is there any other way of determining if GPS is truly enabled?
Thanks.
i think this code should work for you:
//check to see if we have GPS capabilities
if(Titanium.Geolocation.isLocationProviderEnabled(Titanium.Geolocation.PROVIDER_GPS, Titanium.Geolocation.ACCURACY_BEST) == false) {
var alertDlg = Titanium.UI.createAlertDialog({
title:'MileTrackGPS',
message:'GPS is OFF. Enable it in Settings.',
buttonNames: ['Cancel', 'Open Settings']
});
alertDlg.cancel = 0;
alertDlg.addEventListener('click', function(e){
if(!e.cancel) {
//open up the settings page
var settingsIntent = Titanium.Android.createIntent({
action: 'android.settings.LOCATION_SOURCE_SETTINGS'
});
activity.startActivity(settingsIntent);
}
else {
//close the window to exit
win.close();
}
});
alertDlg.show();
}
refrence
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With