【问题标题】:ble device bluetoothdevice.getname() returns null [duplicate]ble设备bluetoothdevice.getname()返回null [重复]
【发布时间】:2015-08-27 05:13:43
【问题描述】:

我正在使用 android 的 Bluetoothgatt 示例应用程序。设备已连接,但 bluetoothdevice.getname() 返回 null。这只发生在 micromax mobile 上。 (它具有 Kitkat 操作系统和蓝牙 4.0 支持)。有没有从设备读取数据的解决方案?我可以在其他手机上获取设备名称和其他特征。

【问题讨论】:

    标签: android bluetooth-lowenergy


    【解决方案1】:

    试试下面的代码。

    public class BLEStateReceiver extends BroadcastReceiver {
    String action = intent.getAction();
        BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
        if(device!= null && device.getType() != BluetoothDevice.DEVICE_TYPE_LE) 
            return;
        if(action.equalsIgnoreCase(BluetoothDevice.ACTION_BOND_STATE_CHANGED)) {
            int extra = intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE, 345);
            switch (extra) {
            case BluetoothDevice.BOND_BONDED:
                BluetoothDevice bondedDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
                if(bondedDevice!= null) {
                    Log.d("TAG", "Bonded device name = " + bondedDevice.getName() + " Bonded Device address ="+bondedDevice.getAddress());
                }
                break;
            }
        }
    

    【讨论】:

    • 我尝试了代码,但什么也没发生example.android.bluetoothlegatt E/: appName=com.example.android.bluetoothlegatt, acAppName=/system/bin/surfaceflinger 08-27 11:15:12.054 11913-11913/com.example.android.bluetoothlegatt E/: 0 in我的原木猫
    • 我也想知道蓝牙 a2dp 是读写数据到 ble 设备所必需的
    猜你喜欢
    • 2014-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-10
    • 1970-01-01
    • 1970-01-01
    • 2019-10-04
    • 2011-11-01
    相关资源
    最近更新 更多