2017-10-05 10 views
0

In meiner App, mit der Schaltfläche für den Standort ein- und ausschalten. Wie Sie diese Schaltfläche mit der Standardpositionsoption (ON oder OFF) abrufen können. Ich bin neu dafür, hilf mir irgendjemandem.Wie bekomme ich die Antwort von Standort an oder aus in Android?

+0

Kasse diesen Code https://stackoverflow.com/a/36173146/1640009 –

+0

danken verwenden Sie @ Ankur_009 – spodee

+0

Ist Aufgabe erledigt? .... –

Antwort

0

Versuchen Sie, diese

  • wenn Sie Location Listener dann versuchen, dieses

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