반응형
Notice
Recent Posts
Recent Comments
«   2024/05   »
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
Archives
Today
Total
관리 메뉴

Do Something IT

[안드로이드] 비행기 모드 On/Off 실시간 체크 처리 본문

Android

[안드로이드] 비행기 모드 On/Off 실시간 체크 처리

아낙시만더 2011. 9. 2. 14:27
반응형

비행기 모드 On/Off 실시간 체크를 하기 위해서는 BroadcastReceiver 가 작동 중이어야한다. 이는 아래와 같이 처리히자. 여기서 state 값이 3이 나오면 전화를 할수 없는 상태이다. 비행기 모드시 전화 신호를 끊어버리니 전화를 할수 없다. 그후 처리를 해주면 된다.


BroadcastReceiver receiver = new BroadcastReceiver() {
			@Override
			public void onReceive(Context context, Intent intent) {
				Log.d("AirplaneMode", "Service state changed   >>> "
						+ intent.getExtras().getInt("state"));
				if (intent.getExtras().getInt("state") == 3) {
					new AlertDialog.Builder(Context)
							.setTitle("실패")
							.setMessage(
									"비행기 모드로 폰이 설정되어 있습니다. 설정 해제후 실행 해주십시요.")
							.setPositiveButton("예",
									new DialogInterface.OnClickListener() {
										public void onClick(
												DialogInterface dialog,
												int which) {
											clearApplicationCache(null); // 캐쉬삭제
											System.exit(0);
										}
									}).setNegativeButton("아니요", null).show();
				}
			}
		};



위 receiver 버에 android.intent.action.SERVICE_STATE를 IntentFilter로 전해준다. 그러면 receiver에서 android.intent.action.SERVICE_STATE를 실시간 감시하게 된다.





IntentFilter intentFilter = new IntentFilter(
				"android.intent.action.SERVICE_STATE");
		registerReceiver(receiver, intentFilter);

반응형
Comments