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

 

About Author

Author Image
Nitin Bhatt

Nitin is an Assistant Project Manager specializing in iOS Application Development. He is an avid reader.

Request for Proposal

Name is required

Comment is required

Sending message..