john john john john - 10 months ago 57
Android Question

Enable GPS setting in Android

I have set up googleMaps in my Application and I want to create an alert box in case the user does not have his/her GPS enabled.

I have everything set up properly but I think I have problem with the following function:

private void launchGPSOptions() {
final ComponentName toLaunch = new ComponentName("","");
final Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivityForResult(intent, 0);

The case which I encounter is that when I have not my GPS enabled and then I press the button for finding my Location instead of dropping me into the GPS settings, is dropping me in the Security settings. I think the fault is the second argument of ComponentName.

Can someone help me finding the right class name for the GPS ?


Create a common class and access this method, as you will require this method to call in multiple places.

public static void showGpsSettings(Context context){
        Intent intent=new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);