2017-10-05 3 views
0

Dans mon application, en utilisant le bouton de commutation pour l'emplacement on et off. Comment récupérer ce bouton avec l'option d'emplacement par défaut (ON ou OFF). Je suis nouveau pour cela, aidez-moi quelqu'un.comment obtenir la réponse de l'emplacement on ou off dans android?

+0

Commander ce code https://stackoverflow.com/a/36173146/1640009 –

+0

merci vous @ Ankur_009 – spodee

+0

Est-ce que la tâche est terminée? .... –

Répondre

0

Essayez cette

  • si vous utilisez Location Listener essayez ce

//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();} 
}