Google 안드로이드 2.1을 사용하여 해당 지역에서 사용 가능한 블루투스 장치 목록을 가져와야합니다.안드로이드에서 사용할 수있는 블루투스 장치를 검색하는 방법은 무엇입니까?
그게, 나는 단지 그 장치의 목록이 필요하지 않습니다, 나는 발견 된 각 장치에 대한 고유 한 ID가 필요하고 지표가 필요합니다. "신호"가 얼마나 좋은지 (안드로이드의 "레벨" .wifi.ScanResult) ... 어떻게해야합니까?
Google 안드로이드 2.1을 사용하여 해당 지역에서 사용 가능한 블루투스 장치 목록을 가져와야합니다.안드로이드에서 사용할 수있는 블루투스 장치를 검색하는 방법은 무엇입니까?
그게, 나는 단지 그 장치의 목록이 필요하지 않습니다, 나는 발견 된 각 장치에 대한 고유 한 ID가 필요하고 지표가 필요합니다. "신호"가 얼마나 좋은지 (안드로이드의 "레벨" .wifi.ScanResult) ... 어떻게해야합니까?
체크 아웃 코드 :
시작 통화 방법 bluetoothScanning은, 문맥이 필요
mBluetoothAdapter.startDiscovery();
mReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
//Finding devices
if (BluetoothDevice.ACTION_FOUND.equals(action))
{
// Get the BluetoothDevice object from the Intent
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
// Add the name and address to an array adapter to show in a ListView
mArrayAdapter.add(device.getName() + "\n" + device.getAddress());
}
}
};
IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
registerReceiver(mReceiver, filter);
검색
void bluetoothScanning(){
IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
context.registerReceiver(mReceiver, filter);
final BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
mBluetoothAdapter.startDiscovery();
}
// Create a BroadcastReceiver for ACTION_FOUND.
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (BluetoothDevice.ACTION_FOUND.equals(action)) {
// Discovery has found a device. Get the BluetoothDevice
// object and its info from the Intent.
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
String deviceName = device.getName();
String deviceHardwareAddress = device.getAddress(); // MAC address
Log.i("Device Name: " , "device " + deviceName);
Log.i("deviceHardwareAddress " , "hard" + deviceHardwareAddress);
}
}
};
결과
이름 : LE-보스 회전 + SoundLink deviceHardwareAddress : MAC 04 : 52 : C7 : D1 : B2 : 76
.....
누군가이 RSSI 관련 경험이 있습니까? 나는 이것이 상수로 정의되기 때문에 조금 불안하다. – xenonite
첫 번째 링크 - http://developer.android.com/guide/topics/wireless/bluetooth.html#FindingDevices가 죽었습니다. – Dayan
링크가 현재 깨졌습니다. – Charlie