-2
如何使用藍牙適配器獲取所有綁定設備的名稱,我需要一個適當的工作代碼,希望有人能幫助我。如何獲取Android中所有藍牙綁定設備的列表?
如何使用藍牙適配器獲取所有綁定設備的名稱,我需要一個適當的工作代碼,希望有人能幫助我。如何獲取Android中所有藍牙綁定設備的列表?
首先確保將這些權限添加到您的應用程序清單文件:
<uses-permission android:name="android.permission.BLUETOOTH"></uses-permission>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"></uses-permission>
現在做:
BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (bluetoothAdapter == null) {
// device doesn't support bluetooth
}
else {
// bluetooth is off, ask user to on it.
if(!bluetoothAdapter.isEnabled()) {
Intent enableAdapter = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableAdapter, 0);
}
// Do whatever you want to do with your bluetoothAdapter
Set<BluetoothDevice> all_devices = bluetoothAdapter.getBondedDevices();
if (all_devices.size() > 0) {
for (BluetoothDevice currentDevice : all_devices) {
log.i("Device Name " + currentDevice.getName());
}
}
}
非常感謝你:) – Androider
的可能的複製[?如何獲得藍牙設備的列表] (http://stackoverflow.com/questions/10795424/how-to-get-the-bluetooth-devices-as-a-list) – FrenchFalcon