[英]How to get only present connected Bluetooth device name in android
I am trying get the connected Bluetooth device name in android.我正在尝试在 android 中获取连接的蓝牙设备名称。
Done like below ,做如下,
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
String name = mBluetoothAdapter.getName();
Log.d(TAG,"name--->"+name);
but I am getting my device name.但我得到了我的设备名称。
You can use Android BluetoothManager您可以使用 Android 蓝牙管理器
following functions you can make use of :您可以使用以下功能:
getConnectionState (BluetoothDevice device, int profile)
getConnectionState (蓝牙设备设备,int 配置文件)
getConnectedDevices (int profile) //get fetch connected device's info
getConnectedDevices (int profile) //获取连接设备的信息
Example :例子 :
BluetoothManager btManager = (BluetoothManager)
mContext.getSystemService(Context.BLUETOOTH_SERVICE);
List<BluetoothDevice> devices =
btManager.getConnectedDevices(BluetoothProfile.GATT);
for(BluetoothDevice device : devices) {
// you will get each device's info here.
}
If you have the mac-address
of the connected device then you can get the device by如果您有所连接设备的
mac-address
,那么您可以通过以下方式获取设备
BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(mac-address);
And to get the name of the connected device并获取连接设备的名称
String connectedDeviceName = device.getName()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.