中mIntentReceiver加入耳机插入的广播处理:
else if (action.equals(Intent.ACTION_HEADSET_PLUG)) {
updateHeadSet(intent);
}
private final void updateHeadSet(Intent intent) {
int state = intent.getIntExtra("state", -1);
int mic = intent.getIntExtra("microphone", -1);
Log.d(TAG, "=========updateHeadSet, state=" + state + ", mic=" + mic + ".");
if (state == -1 || mic == -1) {
return;
}
if (state == 1) {
if (mic == 1) {
mService.setIcon("headset", R.drawable.stat_sys_headset_with_mic, 0, null);
mService.setIconVisibility("headset", true);
} else {
mService.setIcon("headset", R.drawable.stat_sys_headset_without_mic, 0, null);
mService.setIconVisibility("headset", true);
}
// vibrate when headset plug in
Vibrator vibrator = (Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(500);
} else {
mService.setIconVisibility("headset", false);
}
}