首页 > 解决方案 > 经典蓝牙发现没有提供除 MAC 地址以外的详细信息

问题描述

我需要集成蓝牙经典发现并在手机和设备之间建立连接,但发现设备没有在接收器中提供更多详细信息。我的代码是:

final BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
            mBluetoothAdapter = bluetoothManager.getAdapter();
        }else {
                mBluetoothAdapter =BluetoothAdapter.getDefaultAdapter();
            }

        mBluetoothAdapter.startDiscovery();

 public static class Receiver extends BroadcastReceiver{
        @Override
        public void onReceive(Context context, Intent intent) {
            if (BluetoothDevice.ACTION_FOUND.equals(intent.getAction())) {
                BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
                Gson gson=new Gson();
                LogUtils.errorLog("BC ","@@: "+gson.toJsonTree(device));
                //callback.onDeviceFound(device);
            } else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(intent.getAction())) {
                context.unregisterReceiver(this);
                //  callback.onDiscoveryFinished();
            }
        }
    }

标签: androidbluetoothbluetooth-lowenergy

解决方案


关于蓝牙的重要事情是mac地址。获得mac地址后, 1. 可以配对、连接发送和接收数据

例子:

BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(macAddress);
device.getName();
mSocket.connect(createRfcomSecureConnection);

推荐阅读