, когда я пытаюсь записать данные в Mifare classic 1k card, на Nexus S с android 2.3.3 API level 10, у меня возникает эта ошибка. потерпеть неудачу.
мой код
private View.OnClickListener write_butClickListener =new View.OnClickListener() {
@Override
public void onClick(View v) {
IntentFilter ndef=new IntentFilter(NfcAdapter.ACTION_TECH_DISCOVERED );
try{
ndef.addDataType("*/*");
}catch(MalformedMimeTypeException e){
throw new RuntimeException("fail",e);
}
mFilters=new IntentFilter[]{ndef,};
// Setup a tech list for all NfcF tags
mTechLists = new String[][] { new String[] { MifareClassic.class
.getName() } };
Intent intent=getIntent();
String action=intent.getAction();
if(NfcAdapter.ACTION_TECH_DISCOVERED.equals(action) ){
String msg="Discovered Tag with Intent " + intent;
status_Data.setText(msg);
Tag tagFromintent=intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
MifareClassic mfc=MifareClassic.get(tagFromintent);
byte[] data;
try{
mfc.connect();
boolean auth = false;
String cardData = null;
status_Data.setText("Authenticating the Tag..");
auth = mfc.authenticateSectorWithKeyA(1,
MifareClassic.KEY_DEFAULT);
if (auth){
status_Data.setText("Authenticated");
String text = "Hello, World!";
String lang = "en";
byte[] textBytes = text.getBytes();
byte[] langBytes = lang.getBytes("US-ASCII");
int langLength = langBytes.length;
int textLength = textBytes.length;
byte[] payload = new byte[1 + langLength + textLength];
// set status byte (see NDEF spec for actual bits)
payload[0] = (byte) langLength;
// copy langbytes and textbytes into payload
System.arraycopy(langBytes, 0, payload, 1, langLength);
System.arraycopy(textBytes, 0, payload, 1 + langLength, textLength);
if (!mfc.isConnected()) mfc.connect();
mfc.writeBlock(1, payload);
mfc.close();
showMessage("written");
}else{
showMessage("Authetication Failed");
status_Data.setText("");
}
}
catch(IOException e){
status_Data.setText(e.toString());
}
}else{
showMessage("Nothing to read");
}
}
};
любые указатели