如何知道连接的设备是否是OBD?

时间:2014-01-19 23:46:29

标签: android bluetooth

我有一个带有广播接收器的Android应用程序,等待与蓝牙OBD设备的连接。

一旦建立连接,这就是我的BroadcastReceiver

中的示例代码
    if (action.equals(BluetoothDevice.ACTION_ACL_CONNECTED)) {
        BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
        if (/*need this part: condition to check if device is obd */) {
            //do something
        }
    } 

我需要的是如何检查设备是否为obd。

提前致谢!

1 个答案:

答案 0 :(得分:0)

似乎没有api级别的直接解决方案。 OBD设备属于UNCATEGORIZED类别。

您可以使用以下方法获取设备类型:

private String getBluetoothClass(BluetoothDevice device) {

    String bluetoothClassName = "";
    int bluetoothClass = device.getBluetoothClass()
            .getDeviceClass();
    switch (bluetoothClass) {

    case Device.AUDIO_VIDEO_CAMCORDER:
        bluetoothClassName = "AUDIO_VIDEO_CAMCORDER";
        break;
    case Device.AUDIO_VIDEO_CAR_AUDIO:
        bluetoothClassName = "AUDIO_VIDEO_CAR_AUDIO";
        break;
    case Device.AUDIO_VIDEO_HANDSFREE:
        bluetoothClassName = "AUDIO_VIDEO_HANDSFREE";
        break;
    case Device.AUDIO_VIDEO_HEADPHONES:
        bluetoothClassName = "AUDIO_VIDEO_HEADPHONES";
        break;
    case Device.AUDIO_VIDEO_HIFI_AUDIO:
        bluetoothClassName = "AUDIO_VIDEO_HIFI_AUDIO";
        break;
    case Device.AUDIO_VIDEO_LOUDSPEAKER:
        bluetoothClassName = "AUDIO_VIDEO_LOUDSPEAKER";
        break;
    case  Device.AUDIO_VIDEO_MICROPHONE:
        bluetoothClassName = "AUDIO_VIDEO_MICROPHONE";
        break;
    case Device.AUDIO_VIDEO_PORTABLE_AUDIO:
        bluetoothClassName = "AUDIO_VIDEO_PORTABLE_AUDIO";
        break;
    case Device.AUDIO_VIDEO_SET_TOP_BOX:
        bluetoothClassName = "AUDIO_VIDEO_SET_TOP_BOX";
        break;
    case Device.AUDIO_VIDEO_UNCATEGORIZED:
        bluetoothClassName = "AUDIO_VIDEO_UNCATEGORIZED";
        break;
    case Device.AUDIO_VIDEO_VCR:
        bluetoothClassName = "AUDIO_VIDEO_VCR";
        break;
    case Device.AUDIO_VIDEO_VIDEO_CAMERA:
        bluetoothClassName = "AUDIO_VIDEO_VIDEO_CAMERA";
        break;
    case Device.AUDIO_VIDEO_VIDEO_CONFERENCING:
        bluetoothClassName = "AUDIO_VIDEO_VIDEO_CONFERENCING";
        break;
    case Device.AUDIO_VIDEO_VIDEO_DISPLAY_AND_LOUDSPEAKER:
        bluetoothClassName = "AUDIO_VIDEO_VIDEO_DISPLAY_AND_LOUDSPEAKER";
        break;
    case Device.AUDIO_VIDEO_VIDEO_GAMING_TOY:
        bluetoothClassName = "AUDIO_VIDEO_VIDEO_GAMING_TOY";
        break;
    case Device.AUDIO_VIDEO_VIDEO_MONITOR:
        bluetoothClassName = "AUDIO_VIDEO_VIDEO_MONITOR";
        break;
    case Device.AUDIO_VIDEO_WEARABLE_HEADSET:
        bluetoothClassName = "AUDIO_VIDEO_WEARABLE_HEADSET";
        break;
    case Device.COMPUTER_DESKTOP:
        bluetoothClassName = "COMPUTER_DESKTOP";
        break;
    case Device.COMPUTER_HANDHELD_PC_PDA:
        bluetoothClassName = "COMPUTER_HANDHELD_PC_PDA";
        break;
    case Device.COMPUTER_LAPTOP:
        bluetoothClassName = "COMPUTER_LAPTOP";
        break;
    case  Device.COMPUTER_PALM_SIZE_PC_PDA:
        bluetoothClassName = "COMPUTER_PALM_SIZE_PC_PDA";
        break;
    case Device.COMPUTER_SERVER:
        bluetoothClassName = "COMPUTER_SERVER";
        break;
    case Device.COMPUTER_UNCATEGORIZED:
        bluetoothClassName = "COMPUTER_UNCATEGORIZED";
        break;
    case Device.COMPUTER_WEARABLE:
        bluetoothClassName = "COMPUTER_WEARABLE";
        break;
    case Device.HEALTH_BLOOD_PRESSURE:
        bluetoothClassName = "HEALTH_BLOOD_PRESSURE";
        break;
    case Device.HEALTH_DATA_DISPLAY:
        bluetoothClassName = "HEALTH_DATA_DISPLAY";
        break;
    case Device.HEALTH_GLUCOSE:
        bluetoothClassName = "HEALTH_GLUCOSE";
        break;
    case Device.HEALTH_PULSE_OXIMETER:
        bluetoothClassName = "HEALTH_PULSE_OXIMETER";
        break;
    case Device.HEALTH_PULSE_RATE:
        bluetoothClassName = "HEALTH_PULSE_RATE";
        break;
    case Device.HEALTH_THERMOMETER:
        bluetoothClassName = "HEALTH_THERMOMETER";
        break;
    case Device.HEALTH_UNCATEGORIZED:
        bluetoothClassName = "HEALTH_UNCATEGORIZED";
        break;
    case Device.HEALTH_WEIGHING:
        bluetoothClassName = "HEALTH_WEIGHING";
        break;
    case Device.PHONE_CELLULAR:
        bluetoothClassName = "PHONE_CELLULAR";
        break;
    case Device.PHONE_CORDLESS:
        bluetoothClassName = "PHONE_CORDLESS";
        break;
    case Device.PHONE_ISDN:
        bluetoothClassName = "PHONE_ISDN";
        break;
    case Device.PHONE_MODEM_OR_GATEWAY:
        bluetoothClassName = "PHONE_MODEM_OR_GATEWAY";
        break;
    case Device.PHONE_SMART:
        bluetoothClassName = "PHONE_SMART";
        break;
    case Device.PHONE_UNCATEGORIZED:
        bluetoothClassName = "PHONE_UNCATEGORIZED";
        break;
    case Device.TOY_CONTROLLER:
        bluetoothClassName = "TOY_CONTROLLER";
        break;
    case Device.TOY_DOLL_ACTION_FIGURE:
        bluetoothClassName = "TOY_DOLL_ACTION_FIGURE";
        break;
    case Device.TOY_GAME:
        bluetoothClassName = "TOY_GAME";
        break;
    case Device.TOY_ROBOT:
        bluetoothClassName = "TOY_ROBOT";
        break;
    case Device.TOY_UNCATEGORIZED:
        bluetoothClassName = "TOY_UNCATEGORIZED";
        break;
    case Device.TOY_VEHICLE:
        bluetoothClassName = "TOY_VEHICLE";
        break;
    case Device.WEARABLE_GLASSES:
        bluetoothClassName = "WEARABLE_GLASSES";
        break;
    case Device.WEARABLE_HELMET:
        bluetoothClassName = "WEARABLE_HELMET";
        break;
    case Device.WEARABLE_JACKET:
        bluetoothClassName = "WEARABLE_JACKET";
        break;
    case Device.WEARABLE_PAGER:
        bluetoothClassName = "WEARABLE_PAGER";
        break;
    case Device.WEARABLE_UNCATEGORIZED:
        bluetoothClassName = "WEARABLE_UNCATEGORIZED";
        break;
    case Device.WEARABLE_WRIST_WATCH:
        bluetoothClassName = "WEARABLE_WRIST_WATCH";
        break;
    case Device.Major.UNCATEGORIZED:
        bluetoothClassName = "UNCATEGORIZED";
        break;
    default:
        bluetoothClassName = "" + bluetoothClass;
    }

    return bluetoothClassName;
}

您可以将UNCATEGORIZED类型用作主要'过滤器'对于OBD设备:) :)但是为了确认它是一个OBD设备,解决方案是发送一个有效的OBD命令,如ECHO Command(ate0)并检查响应。