赞
踩
首先非常感谢BleLib的作者为我们提供了如此方便的开源库;这个库大大的简化了我们BLE开发的步骤,操作非常简单
dependencies {
compile 'com.junkchen.blelib:blelib:1.2.0'
}
private ServiceConnection serviceConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
mIsBind = true;
mBleService = ((BleService.LocalBinder) service).getService();
//Ble初始化操作
if (mBleService.initialize()) {
//打开蓝牙
if (mBleService.enableBluetooth(true)) {
//Ble扫描回调
mBleService.setOnLeScanListener(leScanListener);
Toast.makeText(getApplicationContext(), "蓝牙已打开", Toast.LENGTH_SHORT).show();
}
} else {
Toast.makeText(getApplicationContext(), "不支持蓝牙", Toast.LENGTH_SHORT).show();
}
}
//绑定服务
private void doBindService() {
Intent serviceIntent = new Intent(this, BleService.class);
bindService(serviceIntent, serviceConnection, Context.BIND_AUTO_CREATE);
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。