android 三星 蓝牙sco,android – 来电后蓝牙SCO失败

我试图通过SCO发送应用程序的所有音频.

我能够成功发送音频,

但是当有来电时,我需要断开SCO表格,以便应用音频不会干扰通话,

问题是,当我尝试在通话后将音频重新路由到SCO时,它不起作用.

这是我用来将音频发送到SCO的代码:

public class BluetoothManager {

// For Bluetooth connectvity

private static String TAG = "BluetoothManager";

private static BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

private static AudioManager aM;

/**

* Set the audio manager of the device.

* @param c: The context this method is called from

*/

public static void setAudioManager(Context c) {

aM = (android.media.AudioManager)c.getSystemService(Context.AUDIO_SERVICE);

}

/**

* Check if a Bluetooth headset is connected. If so, route audio to Bluetooth SCO.

*/

private static void initializeAudioMode(Context context) {

BluetoothProfile.ServiceListener mProfileListener = new BluetoothProfile.ServiceListener() {

public void onServiceConnected(int profile, BluetoothProfile proxy) {

if (profile == BluetoothProfile.HEADSET) {

BluetoothHeadset bh = (BluetoothHeadset) proxy;

List devices = bh.getConnectedDevices();

if (devices.size() > 0) {

enableBluetoothSCO();

}

}

mBluetoothAdapter.closeProfileProxy(profile, proxy);

}

public void onServiceDisconnected(int profile) {}

};

mBluetoothAdapter.getProfileProxy(context, mProfileListener, BluetoothProfile.HEADSET);

}

/**

* Bluetooth Connectvity

* The following methods are associated with enabling/disabling Bluetooth.

* In the future we may want to disable other sources of audio.

*/

private static void enableBluetoothSCO() {

aM.setMode(AudioManager.MODE_IN_CALL);

aM.startBluetoothSco();

aM.setBluetoothScoOn(true);

}

/** Right now, this simply enables Bluetooth */

@SuppressLint("NewApi")

public static boolean enableBluetooth(Context c) {

// If there is an adapter, enable it if not already enabled

if (mBluetoothAdapter != null) {

if (!mBluetoothAdapter.isEnabled()) {

mBluetoothAdapter.enable();

}

setAudioManager(c);

initializeAudioMode(c);

Log.e(TAG, "SCO: " + aM.isBluetoothScoOn());

Log.e(TAG, "A2DP: " + aM.isSpeakerphoneOn());

return true;

} else {

Log.v(TAG, "There is no bluetooth adapter");

return false;

}

}

/** Right now, this simply disables Bluetooth */

public static void disableBluetooth() {

// If there is an adapter, disabled it if not already disabled

if (mBluetoothAdapter != null) {

if (mBluetoothAdapter.isEnabled()) {

mBluetoothAdapter.disable();

}

} else {

Log.v(TAG, "There is no bluetooth adapter");

}

}

public static void restartBluetooth(){

aM.setMode(AudioManager.MODE_IN_CALL);

}

public static void stopBluetooth(){

aM.setMode(AudioManager.MODE_NORMAL);

}

}

当我正确调用stopBluetooth()时,应用程序的音频不再发送到耳机,

但是,当我调用restartBluetooth()时,音频不是按预期播放耳机,而是来自手机扬声器.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值