我目前可以fetchUuidsWithSdp
使用远程设备。(getUuids
不工作,不知道为什么)
但是我怎么能得到我自己的安卓设备的 UUID 呢?
假设当我在服务器套接字上成功执行时,注册的 UUID必须包括我在使用此命令创建服务器套接字时建立的 UUIDaccept()
listenUsingInsecureRfcommWithServiceRecord
我发现情况并非总是如此!我想测试一下。。
嘿有点晚,但我发现最好的方法是做这样的事情。对于生产代码,我不是最好的主意,但对于测试它还不错。
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
Method getUUIDsMethod = BluetoothAdapter.class.getDeclaredMethod("getUuids", null);
ParcelUuid[] dUUIDs = (ParcelUuid[]) getUUIDsMethod.invoke(mBluetoothAdapter, null);
希望这可以帮助
TelephonyManager tManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
String uuid = tManager.getDeviceId();
//or
UUID.nameUUIDFromBytes(tManager.getDeviceId().getBytes("utf8"))