2017-10-05 104 views
0

在我的應用程序中,使用開關按鈕打開和關閉位置。如何使用默認位置選項(ON或OFF)功能獲取此開關按鈕。我是新來的,幫我一個。如何在android中獲取位置響應或關閉?

+0

結帳這個代碼https://stackoverflow.com/a/36173146/1640009 –

+0

謝謝你@ Ankur_009 – spodee

+0

任務完成了嗎? .... –

回答

0

試試這個

  • 如果你使用Location Listener那就試試這個

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