이어폰 연결감지 클래스와 메인 액티비티상의 토글버튼이 동기화를 구현하려고 하는데요.
이어폰이 폰에 꽂히면 버튼이 자동으로 on 뽑으면 off 로 되게 구현을 하려고합니다..
구현을 하는데 도통 감이 안잡혀서 질문드립니다....
고수님들 도와주시면 감사하겠습니다!
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction("android.intent.action.HEADSET_PLUG");
EarphoneMic headsetReceiver = new EarphoneMic();
registerReceiver(headsetReceiver, intentFilter);
넣고
private class EarphoneMic extends BroadcastReceiver{`
@Override
public void onReceive(Context context, Intent intent) {
if (intent.hasExtra("state")) {
if (0 == intent.getIntExtra("state", 0)) {
이어폰이 연결되지 안았으므로 버튼off로 설정
} else if (1 == intent.getIntExtra("state", 0)) {
이어폰이 연결되었으므로 이어폰마이크 버튼 on 설정
}
}
}
}