因此,我正在使用 Eclipse 开发一个 Java BLE Android 模块(对模块和 Appcelerator(制作 Android 应用程序)进行编码)。我正在尝试从 BLE 设备接收数据并将其显示在 Android 手机上。我可以扫描设备并连接到它。
但我真的,真的无法从它那里接收到任何数据。我已经尝试了至少 10 种不同的东西但是......主要问题是我不太了解 BLE API,而且我对 Java 有点菜鸟。谁能帮助可怜的人真正从设备中读取数据?
主要问题是设置蓝牙特征 UUID(我有)。我只是不知道该怎么做...下面是模块的代码...
public class AndroidbleModule extends KrollModule {
public static final String LCAT = "BLE";
private BluetoothManager btManager;
private BluetoothAdapter btAdapter;
private BluetoothDevice btDevice;
private TiApplication appContext;
private Activity activity;
private KrollFunction onFound;
private KrollFunction onConnections;
prvate BluetoothLeScanner btScanner;
private UUID uuid;
BluetoothGatt bluetoothGatt;
BluetoothGattCharacteristic btChar;
BluetoothGattCallbackHandler btData;
KrollDict kd;
Boolean isConnected = false;
BluetoothGatt connectedGatt;
private ScanCallback scanCallback = new ScanCallback() {
@Override
public void onScanResult(int callbackType, ScanResult result) {
BluetoothDevice device = result.getDevice();
if (device != null) {
BluetoothDeviceProxy btDeviceProxy = new
BluetoothDeviceProxy(device);
if (device.getName() != null) {
Log.d(LCAT, "Found: " + device.getName() + " " +
device.getAddress());
ArrayList<String> ids = new ArrayList<String>();
if (device.getUuids() != null) {
for (ParcelUuid id1 : device.getUuids()) {
ids.add(id1.toString());
}
}
btDevice = device;
kd = new KrollDict();
kd.put("name", btDevice.getName());
kd.put("macaddress", btDevice.getAddress());
fireEvent("nb_DevicesFound", kd);
btScanner.stopScan(scanCallback);
}
}
}
};
我希望某个好心人会去天堂怜悯我,帮助我获得那些甜蜜的数据字节。
蝴蝶不菲
米脂
Helenr
相关分类