ble蓝牙技术

/**
  *搜索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;

/**
 *
 * 蓝牙绑定模块初始化
 */
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值