开发者

Problem with UUID and GUID

开发者 https://www.devze.com 2023-03-12 05:44 出处:网络
Please don\'t mark this as duplicate. I have gone through all posts on this topic but couldn\'t solve my problem.

Please don't mark this as duplicate. I have gone through all posts on this topic but couldn't solve my problem.

I have an application in J2ME that searches for bluetooth services with a particular UUID:

UUID[] uuidSet = { new UID("100000",true) };
int[] attrSet = {0x0100, 0x0003, 0x0004};
int transID = agent.searchServices(attrSet,uuidSet,remoteDevice,this);

I have a desktop application in VB.NET using 32feet.NET library that creates a new bluetooth service with a particular GUID.

Sub startBluetoothListener()
    Dim lsnr As New BluetoothListener(MyConsts.MyServiceUuid, record)
    lsnr.Start()
    Dim conn As New BluetoothClient
    Dim peerStream As Stream            
End Sub

Class MyConsts
Public Shared ReadOnly MyServiceUuid As 开发者_如何学编程Guid _
  = New Guid("{7dc53df5-703e-49b3-8670-b1c468f47f1f}")
End Class

Now as per rules, in order to function both GUID/UUID should match. However in .NET the GUID is represented as a hexadecimal string and in JAVA it's different. I googled a lot about how to sync the J2ME and .NET GUID/UUID but could not succeed.


I've read the source for the j2me implementation of UUID, and it simply seems to indicate that you omit the braces and the hyphens i.e. use:

new UUID("7dc53df5703e49b38670b1c468f47f1f", false)

if you use the true parameter, it expects a short-form UUID (i.e. 8 characters long)

My original answer was based on the J2SE implementation, viz:

isn't the constructor for a UUID from a string:

UUID aUUID = UUID.fromString("")

where the string is:

7dc53df5-703e-49b3-8670-b1c468f47f1f

in the case of your UUID (i.e. remove the leading '{' and trailing '}' from the Guid string)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号