Есть ли общая характеристика устройства OBD-II, которая поможет мне определить, является ли это устройством OBD-II?
Мой код, который я пытаюсь подключить к устройству OBD-II по имени.
Код: Выделить всё
// Register a receiver for Bluetooth discovery
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (BluetoothAdapter.ACTION_DISCOVERY_STARTED.equals(action)) {
// Discovery starts. We can show progress
// dialog or perform other tasks
} else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
// Discovery finishes. Dismiss the progress dialog
} else if (BluetoothDevice.ACTION_FOUND.equals(action)) {
// A Bluetooth device was found for pairing
try {
// Here I want to know if the device is OBD-II or not
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
// Make pairing of the OBD-II device as per name:
if (device != null && !device.getName().equals("")) {
LogUtils.LOGE("NEW DEVICE", device.getName());
if (device.getName().equals(OBD_DEVICE_NAME_ONE) ||
device.getName().equals(OBD_DEVICE_NAME_TWO) ||
device.getName().equals(OBD_DEVICE_NAME_THREE)) {
pairDevice(device);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
};
// Send a pairing request to the OBD-II device
private void pairDevice(BluetoothDevice device) {
try {
Method method = device.getClass().getMethod("createBond", (Class[]) null);
method.invoke(device, (Object[]) null);
} catch (Exception e) {
e.printStackTrace();
}
}
Подробнее здесь: https://stackoverflow.com/questions/373 ... -ii-or-not
Мобильная версия