0
我需要通过蓝牙连接一些微控制器设备(传感器芯片)并执行数据读取和发送。Xamarin android蓝牙通信
我已经看到了一些有助于发现,配对和连接到支持蓝牙的设备的示例,但没有太多的数据通信。
我的应用程序需要与传感器芯片谈话,这将不会有用户界面。
我需要通过蓝牙连接一些微控制器设备(传感器芯片)并执行数据读取和发送。Xamarin android蓝牙通信
我已经看到了一些有助于发现,配对和连接到支持蓝牙的设备的示例,但没有太多的数据通信。
我的应用程序需要与传感器芯片谈话,这将不会有用户界面。
我不知道你的传感器芯片是如何工作的。所以我必须假设你已经阅读了你的传感器芯片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" />