Android的蓝牙,找到与空名设备,LG手机上 [英] Android Bluetooth, finds devices with empty names, on LG phone

查看:493
本文介绍了Android的蓝牙,找到与空名设备,LG手机上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经写了一个小BluetoothReceiver,可处理大部分BT状态。

I've written a small BluetoothReceiver, which handles most of the BT states.

该接收器适用于大多数的情景,我把它通过,但在某些情况下,找到的设备有一个名称为空字符串,我不能从另一个告诉一个设备。

The receiver works for most of the scenarios, I put it through, but in some cases the Devices found has an empty string for a name, and I cannot tell one device from another.

下面是调查结果的code段和一块日志进行备份:

Here is the code snippet of the finding and a piece of Log to back it up:

注:BT适配器被关闭,之前的第二检测

另注:这种情况正好发生每秒的时间。第一次的名字被发现,第二次没有名字

ANOTHER NOTE: This scenario happens exactly every second time. The first time the names are found, the second times there are no names

public class BT_Receiver
        extends BroadcastReceiver {
...
    @Override
    public void onReceive(Context context, Intent intent) {
        if (deviceDetectionListener.allDevicesFound())
            return;
        String action = intent.getAction();
        if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(action)) {
            int newState = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, -1);
            state = BT_State.getInstanceForState(newState);
            Toast.makeText(activity, state.name(), Toast.LENGTH_SHORT).show();
            if (state == BT_State.On && enableAndDiscover)
                startDiscoveringDevices();
            return;
        }
        if (BluetoothAdapter.ACTION_DISCOVERY_STARTED.equals(action)) {
            state = BT_State.Discovering;
            Toast.makeText(activity, state.name(), Toast.LENGTH_SHORT).show();
            return;
        }
        if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
            state = BT_State.On;
            Toast.makeText(activity, "Finished discovery", Toast.LENGTH_SHORT).show();
            return;
        }
        if (BluetoothAdapter.ACTION_SCAN_MODE_CHANGED.equals(action)) {
            int discoveryDuration = intent.getIntExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, -1);
            state = BT_State.Advertising;
            Toast.makeText(activity, state.name() + ", duration: " + discoveryDuration, Toast.LENGTH_SHORT).show();
        }
        if (!BluetoothDevice.ACTION_FOUND.equals(action))
            return;
        BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
(Look at the LOG RESULT)       
                    Log.i(TAG, "Bluetooth device found: " + device.getName() + ", " + device.getBluetoothClass() + ", " + device.getAddress());
        deviceDetectionListener.newDeviceDetected(device);
        if (deviceDetectionListener.allDevicesFound())
            detectionCompleted();
    }

...
}

日志的设备名称:

08-15 22:54:16.500: INFO/SOD:BT_Receiver(16151): <!>com.nu.art.software.log.Log 69<!> Bluetooth device found: [bbbb:Demo gizmo 2], 5a0204, 6C:0E:0D:77:B0:96
08-15 22:54:16.578: INFO/SOD:BT_Receiver(16151): <!>com.nu.art.software.log.Log 69<!> Bluetooth device found: [aaaa:Demo gizmo 1], 5a020c, 00:26:CC:81:AF:AD
08-15 22:54:33.820: INFO/SOD:BT_Receiver(16151): <!>com.nu.art.software.log.Log 69<!> Bluetooth device found: Zomaar Iemand, 5a0204, 20:21:A5:C0:CF:6F

另一个日志,而不名称:

08-15 22:54:34.304: INFO/SOD:BT_Receiver(16151): <!>com.nu.art.software.log.Log 69<!> Bluetooth device found: , 5a0204, 00:26:E2:66:31:30
08-15 22:54:36.882: INFO/SOD:BT_Receiver(16151): <!>com.nu.art.software.log.Log 69<!> Bluetooth device found: , 5a0204, 6C:0E:0D:77:B0:96
08-15 22:54:38.601: INFO/SOD:BT_Receiver(16151): <!>com.nu.art.software.log.Log 69<!> Bluetooth device found: , 5a020c, 00:26:CC:81:AF:AD
08-15 22:54:39.820: INFO/SOD:BT_Receiver(16151): <!>com.nu.art.software.log.Log 69<!> Bluetooth device found: , 520204, 78:CA:04:83:45:CD

由于提前,

亚当。

推荐答案

这可能是一个功能不是一个错误,我发现了一个办法解决这个,在情况下,设备没有名字我不救它,如果没有找到设备再次运行查询。

This is probably a feature not a bug, I found a workaround for this, that in case the device does not have a name I don't save it, and if no device was found run the inquiry again.

这篇关于Android的蓝牙,找到与空名设备,LG手机上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆