How to create UUID from string in android

后端 未结 6 1242
Happy的楠姐
Happy的楠姐 2020-12-29 01:53

In my app, I scan low energy Bluetooth for specific service uuid 2415. To convert the string 2415 into uuid I am using UUID serviceUUID = UUID.fromString(

6条回答
  •  攒了一身酷
    2020-12-29 02:16

    I have a feeling that your String "2415" might just have been straight-up converted from a long, because, as the others point out, "2415" is not close to resembling a UUID. If that is the case, then you should use the UUID constructor which takes two longs:

    uuid = new UUID(long mostSignificant, long leastSignificant)

    where you can retrieve those long values via

    uuid.getMostSignificantBits() uuid.getLeastSignificantBits()

    So in your case, you might do something like uuid = new UUID(2415,2415)

提交回复
热议问题