我通过以下方式注册了一项服务
BluetoothServerSocket bs = BluetoothAdapter.getDefaultAdapter().listenUsingInsecureRfcommWithServiceRecord("someName" , UUID.fromString(myUuid) );
我的问题是,是否有任何程序化方式来确定该服务正在使用哪个频道?
============================另一种解决方案==================== ====
:感谢您的回答@Skaard-Solo,但是如果我使用反射来创建套接字,那么我无法为此提供uuid。
我做了一些研究,写了一些简单的函数,可以从 BluetoothServerSocket 获取通道。
public int getChannel(BluetoothServerSocket bsSocket){
Field[] f = bsSocket.getClass().getDeclaredFields();
int channel = -1;
for (Field field : f) {
if(field.getName().equals("mChannel")){
field.setAccessible(true);
try {
channel = field.getInt(bsSocket);
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
field.setAccessible(false);
}
}
return channel;
}