我需要通过蓝牙连接一些微控制器设备(传感器芯片),并执行数据读取和发送。
我看过一些示例,它们有助于发现、配对和连接到支持蓝牙的设备,但在数据通信方面却没有太多帮助。
我的应用程序需要与没有UI的传感器芯片对话。
发布于 2016-08-03 17:41:38
我不知道你的传感器芯片是怎么工作的。所以我不得不假设你已经阅读了你的传感器芯片API文档。我已经修改了我用来连接到另一个蓝牙设备的代码。可能和你的不一样。
BlueToothManager bm; // --> sensor chip manager
// Configure BlueToothManager.
bm= new BlueToothManager (this);
private void initBluetooth() {
// Check if device supports Bluetooth Low Energy.
if (!bm.hasBluetooth()) {
//Toast.makeText(this, "Device does not have Bluetooth Low Energy", Toast.LENGTH_LONG).show();
return;
}
// If Bluetooth is not enabled, let user enable it.
if (!bm.isBluetoothEnabled()) {
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableBtIntent, Constant.REQUEST_ENABLE_BT);
} else {
Log.v(this.getClass(), "---> bluetooth already is enabled");
startBMService(); // --> this function should be from your sensor chip api documents.
}
}顺便说一句,你还必须在清单文件中注册你的服务。下面是一个示例代码。请勿复制,信息应来自您的传感器设备api文档。
<service
android:name=".Service.BMService"
android:exported="false" />
<service
android:name="com.bm.sdk.service.BMService"
android:exported="false" />https://stackoverflow.com/questions/38739723
复制相似问题