我使用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
名称的全名?
答案 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();