In my app, using switch button for location on and off. How to fetch this switch button with default location option(ON or OFF) function. I am new for this ,help me any one.
Asked
Active
Viewed 181 times
0
-
Checkout this code https://stackoverflow.com/a/36173146/1640009 – Ankur_009 Oct 05 '17 at 08:09
-
Is task done? .... – Ankur_009 Oct 05 '17 at 08:45
-
No but can't possible to off globally... – spodee Oct 05 '17 at 09:24
1 Answers
0
Try this
- if you're using
Location Listener
then try this
//take AlertDialog globally
AlertDialog alert;
@Override
public void onProviderDisabled(String provider)
{
// Here you need to call alert of enabling location to get the update
location
showSettingsAlert();
}
@Override
public void onProviderEnabled(String provider)
{
alert.dismiss();
}
public void showSettingsAlert(){
try {
LoginActivity.isGPSAlertShown=true;
alert = new AlertDialog.Builder(mContext).create();
alert.setTitle("GPS is settings");
alert.setCancelable(false);
alert.setMessage("GPS is not enabled. Do you want to go to settings menu?");
alert.setButton(Dialog.BUTTON_POSITIVE, "Settings", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
mContext.startActivity(intent);
isFromSetting = true;
LoginActivity.isGPSAlertShown=false;
}
});
alert.show();
}catch (Exception e){e.printStackTrace();}
}

Community
- 1
- 1

Vishal Yadav
- 1,020
- 4
- 15
- 30