private static IntentFilter plugIntentFilter = new IntentFilter(Intent.ACTION_HEADSET_PLUG);
private static BroadcastReceiver plugStateChangeReceiver = null;
// ** onCreate
plugStateChangeReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
AudioManager audio = (AudioManager) getSystemService(BaseActivity.this.AUDIO_SERVICE);
int systemVolume = audio.getStreamVolume(AudioManager.STREAM_SYSTEM);
// plug状態を取得
isPlugged = (intent.getIntExtra("state", 0) > 0) ? true : false;
if (isPlugged) {
Log.i(null, "Earphone is plugged");
} else {
Log.i(null, "Earphone is unPlugged");
}
}
};
// ** 리스너 등록
// 리스너 등록할때, 플러그 체크도 같이 해줌
registerReceiver(plugStateChangeReceiver, plugIntentFilter);
// ** 리스너 해제
unregisterReceiver(plugStateChangeReceiver);
댓글
댓글 쓰기