Sunday, 15 April 2012

NFC Android writeBlock with KeyB -



NFC Android writeBlock with KeyB -

i have problem android nfc protocol: have device mifare classic, size 4k. seek write block 27, keyb ioexception: trasceive failed. seek write writeblock(int blockindex, byte[] barray) method. authorization true, device connected. same keyb used read sector 27, , operation works properly. same code (with keya) can write in sector 1.

in code below seek write first block of sector 27 (block 108, 108 absolute index of block).

i tried set code mainthread or in sec thread, nil changed. ideas???

……

mynfc.madapter = nfcadapter.getdefaultadapter(this); mynfc.mpendingintent = pendingintent.getactivity(this, 0, new intent(this, getclass()).addflags(intent.flag_activity_single_top), 0); // setup intent filter mime based dispatches intentfilter ndef = new intentfilter(nfcadapter.action_tech_discovered); seek { ndef.adddatatype("*/*"); } grab (malformedmimetypeexception e) { throw new runtimeexception("fail", e); } mynfc.mfilters = new intentfilter[] { ndef, }; // setup tech list nfcf tags mynfc.mtechlists = new string[][] { new string[] { mifareclassic.class.getname() } }; …… seek { tag tagfromintent = intent.getparcelableextra(nfcadapter.extra_tag); mifareclassic mfc = mifareclassic.get(tagfromintent); mynfc.mifareid = tagfromintent.getid(); mynfc.keyb = gymcalcoloalg.gymcalcoloalgorithm(mynfc.mifareid, mynfc.keyb); mfc.connect(); mfc.settimeout(10000); boolean auth = false; auth = mfc.authenticatesectorwithkeyb(27,mynfc.keyb); if (auth) { string text = "hello, world!"; byte[] value = text.getbytes(); byte[] towrite = new byte[mifareclassic.block_size]; (int i=0; i<mifareclassic.block_size; i++) { if (i < value.length) towrite[i] = value[i]; else towrite[i] = 0; } mfc.writeblock(108, towrite); <-- operation failed: ioexception: transceive failed. } } catch(exception ex){ ex.getmessage(); }

android nfc mifare

No comments:

Post a Comment