android 手机怎么实现和蓝牙耳机建立连接,连接之后可以听音乐

移动开发 码拜 8年前 (2016-09-18) 2075次浏览
如题,手机和蓝牙耳机配对之后,怎么建立连接
解决方案

20

BluetoothA2dpService是底层的Service类,你可以通过BluetoothA2dp类来使用它
android.bluetooth.BluetoothA2dp
首先需要绑定BluetoothA2dpService,以下是部分代码:
private BluetoothAdapter mBTAdapter;
private BluetoothA2dp mBTA2DP;
mBTAdapter = BluetoothAdapter.getDefaultAdapter();
mBTAdapter.getProfileProxy(mContext, mProfileServiceListener, BluetoothProfile.A2DP);
private BluetoothProfile.ServiceListener mProfileServiceListener = new BluetoothProfile.ServiceListener() {
@Override
public void onServiceConnected(int profile, BluetoothProfile proxy) {
mBTA2DP = (BluetoothA2dp)proxy;
break;
}
}
取得mBTA2DP实例后,mBTA2DP.connect(BluetoothDevice device); 即可通过A2DP协议连接外设蓝牙设备

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明android 手机怎么实现和蓝牙耳机建立连接,连接之后可以听音乐
喜欢 (0)
[1034331897@qq.com]
分享 (0)