建立BroadcastReceiver的实例。
private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
Log.e("action = " + action);
if (action.equals(Intent.ACTION_HEADSET_PLUG)) {
if (intent.hasExtra("state")) {
int state = intent.getIntExtra("state", 0);
Timber.e("action state = " + state);
handsfree(state == 0);
if (mInCallingDialog != null) {
mInCallingDialog.setAllStatus(isMute, isHandfree);
}
// 0为拔出耳机
}
}
}
};