Android 蓝牙 HFP 和 A2DP
HFP(Hands Free Profile)和 A2DP (Advanced Audio Distribution Profile) 是经典蓝牙常用的两个协议。
HFP 协议一般用来支持耳机打电话、接电话、挂断电话、拒接电话等操作。
A2DP 协议一般用来听歌,传输音频立体声。
ProfileProxy
Android SDK 使用 BluetoothAdapter 的 getProfileProxy 获取每个具体的 Profile。
获取 HFP:
public static boolean getHfpProfileProxy(Context context, BluetoothProfile.ServiceListener listener) {
BluetoothAdapter defaultAdapter = BluetoothAdapter.getDefaultAdapter();
boolean hfp = defaultAdapter.getProfileProxy(context, listener, BluetoothProfile.HEADSET);
return hfp;
}
获取 A2DP:
public static boolean getA2dpProfileProxy(Context context, BluetoothProfile.ServiceListener listener) {
BluetoothAdapter defaultAdapter = BluetoothAdapter.