Open Location Services in Android using Intent Titanium
Posted By : Nitin Bhatt | 01-Jun-2015
In this example you will see how to open location services in Android using Intent.
To open location services in Android use intent. In Android, applications and application components cannot directly communicate with each other. In order to communicate with another application, use an intent.
An Android Intent can be used to perform following tasks :
-Open another Activity or Service from the current Activity.
-Pass data between Activities and Services.
In Titanium app we can check location services is switched on or switched off , if location services switched off we can open alerDialog to notify user location services switched off to open location services click on confirm. when user click on confirm locationSettinsIntent will open android location services in android.
var window = Ti.UI.createWindow({
backgroundImage : "screenBackground.png",
});
function openDialog() {
var locationServicesDialog = Ti.UI.createAlertDialog({
message : 'Open Location Services',
buttonNames : ['Confirm'],
});
locationServicesDialog.show();
locationServicesDialog.addEventListener('click', function(e) {
var locationSettingsIntent = Titanium.Android.createIntent({
action : 'android.settings.LOCATION_SOURCE_SETTINGS'
});
Ti.Android.currentActivity.startActivity(Ti.Android.createIntentChooser(locationSettingsIntent, "Open Settings"));
});
}
window.addEventListener('open', function(e) {
openDialog();
});
window.open();
THANKS
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Nitin Bhatt
Nitin is an Assistant Project Manager specializing in iOS Application Development. He is an avid reader.