NFC写入mifare超轻型EV1 IOException,格式为

时间:2015-07-01 05:28:08

标签: java android nfc mifare

我无法在Nxp Mifare Ultralight EV1标签上写入ndef消息。

CODE:

public class WriteTagTask extends AsyncTask<Void, Void, Void> {
    private Context context;
    private NdefMessage message;
    private Tag tag;


    public WriteTagTask(Context context, NdefMessage message, Tag tag) {
        this.context = context;
        this.message=message;
        this.tag=tag;
    }


    @Override
    protected Void doInBackground(Void... voids) {
        writeTag(message,tag);
        return null;
    }


    /*
    * Writes an NdefMessage to a NFC tag
    */
    public boolean writeTag(NdefMessage message, Tag tag) {
        int size = message.toByteArray().length;
        Log.i("writeTag", "size " + size);
        try {

                NdefFormatable format = NdefFormatable.get(tag);
                if (format != null) {
                    Log.i("writeTag", "NdefFormatable ");
                    try {
                        format.connect();
                        format.format(message);//IO EXCEPTION
                        Log.i("writeTag", "NdefFormatable true");
                        return true;
                    } catch (IOException e) {
                        e.printStackTrace();
                        Toast.makeText(context,
                                "Error: write failed!!",
                                Toast.LENGTH_SHORT).show();
                        return false;
                    }
                } else {
                    return false;
                }
            }
        } catch (Exception e) {
            return false;
        }
    }
}

我在format.format(message);

中得到以下IO异常
07-01 10:01:18.094  14243-14243/com.aarfid.tickettagwriter W/System.err﹕ java.io.IOException
07-01 10:01:18.094  14243-14243/com.aarfid.tickettagwriter W/System.err﹕ at android.nfc.tech.NdefFormatable.format

(NdefFormatable.java:132)
07-01 10:01:18.094  14243-14243/com.aarfid.tickettagwriter W/System.err﹕ at android.nfc.tech.NdefFormatable.format

(NdefFormatable.java:95)
07-01 10:01:18.094  14243-14243/com.aarfid.tickettagwriter W/System.err﹕ at 

com.aarfid.tickettagwriter.MainActivity.writeTag(MainActivity.java:237)
07-01 10:01:18.094  14243-14243/com.aarfid.tickettagwriter W/System.err﹕ at 

com.aarfid.tickettagwriter.MainActivity.onNewIntent(MainActivity.java:117)
07-01 10:01:18.094  14243-14243/com.aarfid.tickettagwriter W/System.err﹕ at 

android.app.Instrumentation.callActivityOnNewIntent(Instrumentation.java:1161)
07-01 10:01:18.094  14243-14243/com.aarfid.tickettagwriter W/System.err﹕ at android.app.ActivityThread.deliverNewIntents

(ActivityThread.java:2365)
07-01 10:01:18.094  14243-14243/com.aarfid.tickettagwriter W/System.err﹕ at android.app.ActivityThread.performNewIntents

(ActivityThread.java:2378)
07-01 10:01:18.094  14243-14243/com.aarfid.tickettagwriter W/System.err﹕ at android.app.ActivityThread.handleNewIntent

(ActivityThread.java:2387)
07-01 10:01:18.094  14243-14243/com.aarfid.tickettagwriter W/System.err﹕ at android.app.ActivityThread.access$1600

(ActivityThread.java:145)
07-01 10:01:18.094  14243-14243/com.aarfid.tickettagwriter W/System.err﹕ at android.app.ActivityThread$H.handleMessage

(ActivityThread.java:1314)
07-01 10:01:18.094  14243-14243/com.aarfid.tickettagwriter W/System.err﹕ at android.os.Handler.dispatchMessage

(Handler.java:102)
07-01 10:01:18.094  14243-14243/com.aarfid.tickettagwriter W/System.err﹕ at android.os.Looper.loop(Looper.java:136)
07-01 10:01:18.094  14243-14243/com.aarfid.tickettagwriter W/System.err﹕ at android.app.ActivityThread.main

(ActivityThread.java:5136)
07-01 10:01:18.094  14243-14243/com.aarfid.tickettagwriter W/System.err﹕ at java.lang.reflect.Method.invokeNative(Native 

Method)
07-01 10:01:18.094  14243-14243/com.aarfid.tickettagwriter W/System.err﹕ at java.lang.reflect.Method.invoke

(Method.java:515)
07-01 10:01:18.094  14243-14243/com.aarfid.tickettagwriter W/System.err﹕ at com.android.internal.os.ZygoteInit

$MethodAndArgsCaller.run(ZygoteInit.java:819)
07-01 10:01:18.094  14243-14243/com.aarfid.tickettagwriter W/System.err﹕ at com.android.internal.os.ZygoteInit.main

(ZygoteInit.java:635)
07-01 10:01:18.094  14243-14243/com.aarfid.tickettagwriter W/System.err﹕ at dalvik.system.NativeStart.main(Native Method)

我尝试使用Play商店中提供的一些应用程序在此标签上书写,但他们也写错误。

  

是否可以使用android的Ndefformatable在此标签上书写   或者我必须使用ISO 14443命令吗?

enter image description here

修改

数据:第2页是保留,第3页是OTP,第16页是配置,第18页是认证密码&amp;第19页是密码确认。

enter image description here

由于

0 个答案:

没有答案