누군가는 블루투스가 다른 기기 (휴대폰, 헤드셋 등)블루투스가 연결되어 있는지 확인하는 방법은 무엇입니까?
2
A
답변
4
나는 현재 연결된 장치의 목록을 얻을 수있는 방법을 알고하지 않습니다,하지만 당신은 ACL_CONNECTED 의도 사용하여 새 연결을 수신 할 수 http://developer.android.com/reference/android/bluetooth/BluetoothDevice.html#ACTION_ACL_CONNECTED
이 INTE을 nt는 연결이있는 원격 장치의 추가 필드를 포함합니다.
Android에서 모든 Bluetooth 연결은 ACL 연결이므로이 인 텐트를 등록하면 새로운 연결이 모두 제공됩니다.
따라서, 수신기는 다음과 같이 보일 것입니다 :
public class ReceiverBlue extends BroadcastReceiver {
public final static String CTAG = "ReceiverBlue";
public Set<BluetoothDevice> connectedDevices = new HashSet<BluetoothDevice>();
public void onReceive(Context ctx, Intent intent) {
final BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
if (BluetoothDevice.ACTION_ACL_CONNECTED.equalsIgnoreCase(action)) {
Log.v(CTAG, "We are now connected to " + device.getName());
if (!connectedDevices.contains(device))
connectedDevices.add(device);
}
if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equalsIgnoreCase(action)) {
Log.v(CTAG, "We have just disconnected from " + device.getName());
connectedDevices.remove(device);
}
}
}
0
에 연결되어있는 경우 내가 찾을 수있는 방법을 가르쳐 수 있습니까 getBondedDevices는() 당신 :
Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
// If there are paired devices
if (pairedDevices.size() > 0) {
// Loop through paired devices
for (BluetoothDevice device : pairedDevices) {
// Add the name and address to an array adapter to show in a ListView
mArrayAdapter.add(device.getName() + "\n" + device.getAddress());
}
}
감사합니다 :) 도움이 될 것입니다 생각
나는 이것을 시도했다. 내가 장치를 연결할 때마다 그것은 "ACTION_ACL_CONNECTED"를 보여줍니다. 그러나 그것은 즉시 "ACTION_ACL_DISCONNECTED"를 보여줍니다. 나는 잘못된 것을하고 있습니까? –
이상합니다. 연결이 짧게 유지 된 다음 손실되는 것처럼 들립니다. 나는 왜 당신이 그것을 얻고 있는지 잘 모르겠습니다. – Tom
'Android에서 모든 블루투스 연결은 ACL 연결입니다. '당신은 틀림 없습니까? 그 링크가있어?! – Soheil