如何获得Android蓝牙的全名

时间:2014-05-27 13:53:10

标签: android bluetooth

我使用startDiscovery()BroadcastReceiver来搜索附近的Bluetooth设备。

private BroadcastReceiver receiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        if (action.equals(BluetoothDevice.ACTION_FOUND)) {
            BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
            String btname = device.getName();
            }
        }
        if (action.equals(ActivityControlCenter.ACTIVITY_EXIT_ACTION)){
            finish();
        }
    }
};

由于我需要使用Bluetooth名称来传输某些消息,因此我将Bluetooth名称设置为大约40到150个字节(最大值为248)。但是,我从btname获得的device.getName()不是我设置的全名。

如何获取Bluetooth名称的全名?

1 个答案:

答案 0 :(得分:0)

试试这个......

BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
// if device does not support Bluetooth
if(mBluetoothAdapter==null){
    Log.d(TAG,"device does not support bluetooth");
    return null;
}
String bluetoothname = mBluetoothAdapter.getName();