/**
*搜索BLE终端
*
*/
public class BleManager{
private BluetoothManager bluetoothManager;
public static BluetoothAdapter mBluetoothAdapter;
public BleManager(Context mContext){
bluetoothManager = (BluetoothManager) context.getSystemService(Context.BLUETOOTH_SERVICE);
mBluetoothAdapter = bluetoothManager.getAdapter();
}
/**
*蓝牙状态 - 模块
*/
/**
* 判断是否支持蓝牙
* @return
*/
public boolean isSupportBle(){
if(mBluetoothAdapter == null){
return false;
}
return true;
}
/**
* 得到蓝牙当前状态
* @return
*/
public boolean bleIsEnabled(){
Log.e("ble" , "ble.isEnabled() = " + mBluetoothAdapter.isEnabled());
return mBluetoothAdapter.isEnabled();
}
/**
* 打开蓝牙
*/
public void openBle(){
mBluetoothAdapter.enable();
}
/**
* 打开蓝牙 - 调用系统方法 - dialog显示
*/
private void openBle() {
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
}
/**
*蓝牙扫描 模块
*/
1、开始扫描: mBluetoothAdapter.startLeScan(mLeScanCallback);
2、停止扫描:
mBluetoothAdapter.stopLeScan(mLeScanCallback)
3、ble扫描回调:
private BluetoothAdapter.LeScanCallback mLeScanCallback = new BluetoothAdapter.LeScanCallback() {
public void onLeScan(final BluetoothDevice device, int rssi, byte[] scanRecord) {
}
}
/**
*蓝牙绑定 模块
*/
/** 需复制BluetoothLeClass.java文件至项目中 */
1、初始化BluetoothLeClass的对象
private BluetoothLeClass mBLE;
BluetoothGattCharacteristic MyAttCharacteristic;
/** * * 蓝牙绑定模块初始化 */