Java 当前连接的蓝牙设备android

Java 当前连接的蓝牙设备android,java,android,bluetooth,connection,device,Java,Android,Bluetooth,Connection,Device,我可以在Android中看到蓝牙设备的两种状态。 1.成对的 2.连接- 我正在尝试在Android中获取当前已连接的蓝牙设备。但我只从adapter.getBondedDevices()获取配对设备列表我需要当前连接的设备。我怎样才能得到这个。请有人帮我做到这一点。提前感谢。将此添加到您的清单文件中 <receiver android:name=".MyBluetoothReceiver" > <intent-filter> <action android:nam

我可以在Android中看到蓝牙设备的两种状态。 1.成对的 2.连接-

我正在尝试在Android中获取当前已连接的蓝牙设备。但我只从
adapter.getBondedDevices()获取配对设备列表我需要当前连接的设备。我怎样才能得到这个。请有人帮我做到这一点。提前感谢。

将此添加到您的清单文件中
<receiver android:name=".MyBluetoothReceiver" >
<intent-filter>
<action android:name="android.bluetooth.device.action.ACL_CONNECTED" />
<action android:name="android.bluetooth.device.action.ACL_DISCONNECTED" 
/>
<action 
android:name="android.bluetooth.device.action.ACL_DISCONNECT_REQUESTED" 
/>           
</intent-filter>  
</receiver>  

<receiver android:name=".MyBluetoothReceiver" >
<intent-filter>
<action android:name="android.bluetooth.device.action.ACL_CONNECTED" />
<action android:name="android.bluetooth.device.action.ACL_DISCONNECTED" 
/>
<action 
android:name="android.bluetooth.device.action.ACL_DISCONNECT_REQUESTED" 
/>           
</intent-filter>  
</receiver>  

这很直截了当。安卓有什么方法

<receiver android:name=".MyBluetoothReceiver" >
<intent-filter>
<action android:name="android.bluetooth.device.action.ACL_CONNECTED" />
<action android:name="android.bluetooth.device.action.ACL_DISCONNECTED" 
/>
<action 
android:name="android.bluetooth.device.action.ACL_DISCONNECT_REQUESTED" 
/>           
</intent-filter>  
</receiver>  
getConnectedDevices()

<receiver android:name=".MyBluetoothReceiver" >
<intent-filter>
<action android:name="android.bluetooth.device.action.ACL_CONNECTED" />
<action android:name="android.bluetooth.device.action.ACL_DISCONNECTED" 
/>
<action 
android:name="android.bluetooth.device.action.ACL_DISCONNECT_REQUESTED" 
/>           
</intent-filter>  
</receiver>  
实施方式如下:

<receiver android:name=".MyBluetoothReceiver" >
<intent-filter>
<action android:name="android.bluetooth.device.action.ACL_CONNECTED" />
<action android:name="android.bluetooth.device.action.ACL_DISCONNECTED" 
/>
<action 
android:name="android.bluetooth.device.action.ACL_DISCONNECT_REQUESTED" 
/>           
</intent-filter>  
</receiver>  
BluetoothManager manager = (BluetoothManager) getSystemService(BLUETOOTH_SERVICE);
    List<BluetoothDevice> connected = manager.getConnectedDevices(GATT);
    Log.i("Connected Devices: ", connected.size()+"");

希望对您有所帮助:)

使用此权限也请检查此链接,该问题对我来说并不完全清楚。你到底是做什么的?在执行btlDevice.createrFComSocketToServiceRecord(MY_UUID)时创建连接的btlDevice;或者,系统使用最后连接的BTL设备。请更详细地说明你在做什么。检查这个我发现了一个解决方案,它在android 10上工作。这只会在设备连接时发出通知。如果设备已连接,然后您启动应用程序,该怎么办。?如何连接设备?您有@GNK。对不起,没有。我不需要做这个了。要从Android设置界面查看BT设备,也许您可以在设置应用程序源代码时签出。我已经看到了这一点,但它相当复杂。此外,问题下的注释(对于Android 10)可能有助于设置
GATT=BluetoothProfile.GATT\u服务器
,也可以工作
<receiver android:name=".MyBluetoothReceiver" >
<intent-filter>
<action android:name="android.bluetooth.device.action.ACL_CONNECTED" />
<action android:name="android.bluetooth.device.action.ACL_DISCONNECTED" 
/>
<action 
android:name="android.bluetooth.device.action.ACL_DISCONNECT_REQUESTED" 
/>           
</intent-filter>  
</receiver>