我正在尝试将我的设备连接到支持A2DP和HFP的蓝牙扬声器。
我设法让设备连接到A2DP,但是点击一个按钮,我希望它能够解决任何对扬声器的呼叫,如果我再次按下按钮,它应该取消,并且所有呼叫将被路由回电话。 出于某种原因,它不会转移我尝试不同方式的电话,这是我现在达到的那个
static PhoneStateListener phoneStateListener = new PhoneStateListener() {
@Override
public void onCallStateChanged(int state, String incomingNumber) {
if(DataHolder.SPEAKER_PHONE){
if (state == TelephonyManager.CALL_STATE_RINGING) {
am2.setMode(AudioManager.MODE_RINGTONE);
} else if (state == TelephonyManager.CALL_STATE_IDLE) {
am2.setMode(AudioManager.MODE_NORMAL);
} else if (state == TelephonyManager.CALL_STATE_OFFHOOK) {
am2.setMode(AudioManager.MODE_IN_CALL);
}
}
super.onCallStateChanged(state, incomingNumber);
}
};
public static void transferCalls(){
telephonyManager = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE);
if (telephonyManager != null) {
telephonyManager.listen(phoneStateListener,
PhoneStateListener.LISTEN_CALL_STATE);
}
am2.setBluetoothScoOn(true);
am2.startBluetoothSco();
}
public static void stopTransferCalls(){
am2.stopBluetoothSco();
am2.setBluetoothScoOn(false);
am2.setSpeakerphoneOn(true);
am2.setMode(AudioManager.MODE_NORMAL);
am2.abandonAudioFocus(new OnAudioFocusChangeListener() {
@Override
public void onAudioFocusChange(int focusChange) {
}
});
}