Thursday, April 11, 2013

[android help] Writting an image using NdefMessage


I am trying to write an image on a Ndef Tag, currently, i am able to write it, but when I try to read it with any market application, they treat it like a text message. here is my piece of code writing the image :



Bitmap mBitmap = Bitmap.createScaledBitmap(mPhoto, 100, 100, true);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
mBitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
NdefRecord picRecord = new NdefRecord(NdefRecord.TNF_MIME_MEDIA, "image/png".getBytes(), null, byteArray);
String informations = "name: "+name + "\ntitle: " + title + "\naddress: "+ address + "\ncity: "+ city + "\nphone: "+ phone + "\nmail: "+mail;
NdefRecord textRecord = createTextRecord(informations);
NdefMessage message = new NdefMessage(new NdefRecord[]{picRecord, textRecord});


i also tryed writting the image this way :



NdefMessage msg = new NdefMessage(new NdefRecord[] {createMimeRecord("image/png", byteArray), textRecord});


with the method createMimeRecord :



public NdefRecord createMimeRecord(String mimeType, byte[]payload) {
byte[] mimeBytes = mimeType.getBytes(Charset.forName("USASCII"));
NdefRecord mimeRecord = new
NdefRecord(NdefRecord.TNF_MIME_MEDIA,
mimeBytes, new byte[0], payload);
return mimeRecord;
}


Here is the result i get when trying to read my image with applications like "TagInfo" :enter image description here


The text message is well writen and can be read normally. I've tried to use the "createMime(String mime type, byte[] data) but this method seems "undefined".I've tried to compress the bitmap image in Jpeg format with the same result. Also I've tried to find examples of sending images via NdefMessages, but didn't find any. Any suggestion ?



.

stackoverflow.comm

No comments:

Post a Comment

Google Voice on T-Mobile? [General]

Google Voice on T-Mobile? So I recently switched from a GNex on Verizon to a Moto X DE on T-Mobile. I had always used Google Voice for my v...