ble蓝牙连接
申请权限
ble蓝牙连接需要权限,在manifest中声明蓝牙相关权限
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
同时,也需要定位权限,用来扫描蓝牙
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
获取蓝牙适配器
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
adapter.getProfileProxy(getApplicationContext(), new BluetoothProfile.ServiceListener() {
@Override
public void onServiceConnected(int profile, BluetoothProfile proxy) {
//获取profile,可以通过profile知道设备的绑定、连接等情况
}
@Override
public void onServiceDisconnected(int profile) {