我正在编写一个应用程序,该应用程序需要知道您是拨打电话还是接听电话,音频是否将通过设备或连接的蓝牙耳机进行路由。
我能够检测到是否连接了头戴式耳机,并且是否可以按以下方式接收和发送音频:
public static boolean isBluetoothHeadsetConnected(Context ctx) {
BluetoothAdapter mBluetoothAdapter =
BluetoothAdapter.getDefaultAdapter();
AudioManager am = (AudioManager)ctx.getSystemService(Context.AUDIO_SERVICE);
boolean btin = false;
boolean btout = false;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
for (AudioDeviceInfo info: am.getDevices(AudioManager.GET_DEVICES_ALL)){
if ((info.getType()==AudioDeviceInfo.TYPE_BLUETOOTH_A2DP)||(info.getType()==AudioDeviceInfo.TYPE_BLUETOOTH_SCO)){
if (info.isSink()){
btin = true;
} else {
btout = true;
}
}
}
} else {
btin = true;
btout = true;
}
return mBluetoothAdapter != null && mBluetoothAdapter.isEnabled()
&& (mBluetoothAdapter.getProfileConnectionState(BluetoothHeadset.HEADSET) == BluetoothHeadset.STATE_CONNECTED)
&& (btin&&btout);
}
但是我发现某些设备(特别是Galaxy Watches)为此将返回“ true”(它们具有头戴式耳机功能并可以路由音频),但是如果您拨打电话或接听电话,则默认情况下不会通过它们路由。
AudioManager getRouting 已过时, isBluetoothScoOn()仅在实际流式传输时有效。
是否可以知道拨打/接听电话时音频会到达哪里?