Question

I was looking for QR code example. And I found the below link for creating QR code from a string. This solution is working fine but if I have a class lets say Student and have fields: id,name,phone. Then create an object of Student class and want to make QR code out of all the info of an object(Which should be information of 1 student).

How am I going to do it? And after making the QR code, how am I going to retrieve it back to the original object?

Was it helpful?

Solution

A QR code can contains arbitrary text, so you can implement a toString/fromString serializer/desserializer in your Student class.

A QRCode can contains up to 4296 alpha-numeric chars (be careful with this limit)

A suggestion : you can use Json format since there a lot of libraries available to help you in serialization/desserialization process.


If you decide to use Json : you can use the gson library.

Serialization is as simple as calling

public String serialize(){
    return new Gson().toJson(this);
}

And for deserialization,

public static Student deserialize(String jsonString){
    new Gson().fromJson(jsonStr, Student.class);
}

more about Json on Android here

OTHER TIPS

You have to find some way to serialise your class (http://en.wikipedia.org/wiki/Serialization)

You can consider JSON but using some binary format like protobuffers (https://developers.google.com/protocol-buffers/) you will be able to fit more data into qrcodes of the same size.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top