위치 정보가 필요한 어플 개발시에 GPS의 Enable/Disable 상태를 확인하고 필요할 경우 GSP 설정을 바꿔 줘어야 한다.
그런데 알아본 결과 어플에서 바로 GPS의 설정은 변경할 수 없는거 같다. 사용자가 직접 시스템 UI 또는 전문적인 어플을 통해서 변경을 하여야 한다. 그래서 어플에서는 GPS의 상태를 검사해서 Disable 상태일 경우 사용자가 직접 GPS 상태를 변경하도록 GPS 설정창으로 넘겨주는 것까지만 해주면 된다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | public void onCreate(Bundle savedInstanceState) { // ...... // Check GPS Enable LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); if(!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { createGpsDisabledAlert(); } // ...... } // GPS Disabled Alert private void createGpsDisabledAlert() { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage("Your GPS is disabled! Would you like to enable it?") .setCancelable(false) .setPositiveButton("Enable GPS", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { showGpsOptions(); } }) .setNegativeButton("Do nothing", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); AlertDialog alert = builder.create(); alert.show(); } // show GPS Options private void showGpsOptions() { Intent gpsOptionsIntent = new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS); startActivity(gpsOptionsIntent); } |