Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to redirect towards GPS setting window in Android or iOS using Phonegap for on or off a GPS

I want to implement a functionality like Native android in Phonegap in which when user want to enable GPS at that time via button click it will be redirected to setting section of android or IOS so that user can on the button of GPS.

Because programmatically we can not directly on or off the GPS on the device, we can only redirect the user to setting, so how to redirect it to setting in Phonegap for both Android and iOS.

I want to implement below functionality in Phonegap.

/**
 * Function to check if best network provider
 * @return boolean
 * */
public boolean canGetLocation() {
    return this.canGetLocation;
}

/**
 * Function to show settings alert dialog
 * */
public void showSettingsAlert(){
    AlertDialog.Builder alertDialog = new AlertDialog.Builder(mContext);

    // Setting Dialog Title
    alertDialog.setTitle("GPS is settings");

    // Setting Dialog Message
    alertDialog.setMessage("GPS is not enabled. Do you want to go to settings menu?");

    // Setting Icon to Dialog
    //alertDialog.setIcon(R.drawable.delete);

    // On pressing Settings button
    alertDialog.setPositiveButton("Settings", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog,int which) {
            Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
            mContext.startActivity(intent);
        }
    });

    // on pressing cancel button
    alertDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
        dialog.cancel();
        }
    });

    // Showing Alert Message
    alertDialog.show();
}
like image 305
Abdulqadir_WDDN Avatar asked Jan 31 '13 06:01

Abdulqadir_WDDN


1 Answers

startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));

try this intent friend it take you to location settings...

like image 148
Venkatesh S Avatar answered Oct 20 '22 15:10

Venkatesh S