0

Mifare Classic カードを読み取ろうとしていますが、認証ステップで失敗します。A と B の両方の認証方法を試しました。

私もこの 質問に精通しており、Mifare Classic カード/タグを読み取ることができない電話のリストへの参照を見つけるこのページも読みました。

私が使用している電話はLG Optimus L5 II E460です。使ったことある方いますか?

電話がMifare Classicカード/タグを読み取れるかどうか、アプリケーション内で確認する方法はありますか?

MifareClassic.KEY_DEFAULT ではなく個人キーで Mifare Classic カード/タグをロックする方法はありますか?

Mifare Classic カード/タグをフォーマットする方法はありますか? フォーマットとは、 Factory Resetのように、カード/タグからすべてを消去することを意味します。

これが私のコードです:

public class NFC_Writer extends AppCompatActivity {

private NfcAdapter mNfcAdapter;
private Tag mTag;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_nfc__writer);

    mNfcAdapter = NfcAdapter.getDefaultAdapter(this);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_nfc__writer, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}

@Override
protected void onResume() {
    super.onResume();

    enableForegroungDispatchSystem();
}

@Override
protected void onPause() {
    super.onPause();

    disableForegroungDispatchSystem();
}

@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);

    if(intent.hasExtra(NfcAdapter.EXTRA_TAG))
    {
        Toast.makeText(this, "We received a NFC intent!", Toast.LENGTH_SHORT).show();

        mTag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);

        String[] techList = mTag.getTechList();

        //writeCard(message);

        EditText editText = (EditText) this.findViewById(R.id.entered_text);
        String message = editText.getText().toString();

        NdefMessage ndefMessage = createNdefMessage(message);

        writeNdefMessage(mTag, ndefMessage);
    }
}

private void enableForegroungDispatchSystem(){

    Intent intent = new Intent(this, NFC_Writer.class).addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);

    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);

    IntentFilter[] intentFilters = new IntentFilter[] {};

    mNfcAdapter.enableForegroundDispatch(this, pendingIntent, intentFilters, null);
}

private void disableForegroungDispatchSystem(){
    mNfcAdapter.disableForegroundDispatch(this);
}


private void formatTag(Tag tag, NdefMessage ndefMessage){
    try{
        NdefFormatable ndefFormatable = NdefFormatable.get(tag);

        if(null == ndefFormatable){
            Toast.makeText(this, "Tag is not ndef formatable", Toast.LENGTH_SHORT).show();
        }

        ndefFormatable.connect();
        ndefFormatable.format(ndefMessage);
        ndefFormatable.close();
    }
    catch(Exception e){
        Log.e("formatTag", e.getMessage());
        Toast.makeText(this, "Tot avem exceptie in formatTag " + e.getMessage(), Toast.LENGTH_SHORT).show();
    }
}

private void writeNdefMessage(Tag tag, NdefMessage ndefMessage){
    try{
        if (null == tag) {
            Toast.makeText(this, "Tag object cannot be NULL!", Toast.LENGTH_SHORT).show();
            return;
        }

        Ndef ndef = Ndef.get(tag);

        if (null == ndef) {
            formatTag(tag, ndefMessage);
        }
        else{
            ndef.connect();

            if (false == ndef.isWritable()) {
                Toast.makeText(this, "Tag is not writable!", Toast.LENGTH_SHORT).show();

                ndef.close();

                return;
            }

            ndef.writeNdefMessage(ndefMessage);

            ndef.close();
        }

        Toast.makeText(this, "Tag written!", Toast.LENGTH_SHORT).show();
    }
    catch (Exception e){
        Log.e("writeNdefMessage", e.getMessage());
    }
}

private NdefRecord createTextRecord(String content){
    try{
        byte[] language;

        language = Locale.getDefault().getLanguage().getBytes("UTF-8");

        final byte[] text = content.getBytes("UTF-8");
        final int languageSize = language.length;
        final int textlength = text.length;
        final ByteArrayOutputStream payload = new ByteArrayOutputStream(1 + languageSize + textlength);

        payload.write( (byte)(languageSize & 0x1F));
        payload.write(language, 0, languageSize);
        payload.write(text, 0, textlength);

        return new NdefRecord(NdefRecord.TNF_WELL_KNOWN, NdefRecord.RTD_TEXT, new byte[0], payload.toByteArray());
    }
    catch(UnsupportedEncodingException e){
        Log.e("createtextRecord", e.getMessage());
    }

    return null;
}

private NdefMessage createNdefMessage(String content){

    NdefRecord ndefRecord = createTextRecord(content);

    NdefMessage ndefMessage = new NdefMessage(new NdefRecord[] {ndefRecord});

    return ndefMessage;
}

private void writeCard(String content){
    MifareClassic mfc = MifareClassic.get(mTag);

    try{
        mfc.connect();
        {
            boolean authA = mfc.authenticateSectorWithKeyB(0, MifareClassic.KEY_DEFAULT);

            Toast.makeText(this, "writeCard() : " + String.valueOf(authA) + " ", Toast.LENGTH_SHORT).show();

            mfc.writeBlock(mfc.sectorToBlock(1), new byte[]{'A', 'l', 'v', 'a', 'r', 'e', 'z', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '});
        }
        mfc.close();
    }
    catch(Exception ioe) {
        Log.e("writeCard : ", ioe.getMessage());
    }
}
}

Ndef を使用するためにNdefFormatableを使用してカードをフォーマットしようとしましたが、 NdefFormatable ::connect()関数を呼び出すとIOExceptionがスローされます。

MifareClassicクラスを使用しようとすると、関数authenticateSectorWithKeyBまたはauthenticateSectorWithKeyAを呼び出すと、常にfalseを受け取ります。

Tag ::getTechList()呼び出すと、次のリストを受け取るため、この両方の方法を試しまし

すべてのログは次のとおりです。

10-08 19:35:34.906    6649-6649/? D/dalvikvm﹕ Late-enabling CheckJNI
10-08 19:35:34.948    6649-6649/com.example.bosutar_cosmin.nfc_writer E/Trace﹕ error opening trace file: No such file or directory (2)
10-08 19:35:34.961    6649-6649/com.example.bosutar_cosmin.nfc_writer V/ActivityThread﹕ Class path: /data/app/com.example.bosutar_cosmin.nfc_writer-1.apk, JNI path: /data/data/com.example.bosutar_cosmin.nfc_writer/lib
10-08 19:35:35.014    6649-6649/com.example.bosutar_cosmin.nfc_writer W/dalvikvm﹕ VFY: unable to find class referenced in signature (Landroid/view/SearchEvent;)
10-08 19:35:35.014    6649-6649/com.example.bosutar_cosmin.nfc_writer I/dalvikvm﹕ Could not find method android.view.Window$Callback.onSearchRequested, referenced from method android.support.v7.internal.view.WindowCallbackWrapper.onSearchRequested
10-08 19:35:35.014    6649-6649/com.example.bosutar_cosmin.nfc_writer W/dalvikvm﹕ VFY: unable to resolve interface method 14076: Landroid/view/Window$Callback;.onSearchRequested (Landroid/view/SearchEvent;)Z
10-08 19:35:35.015    6649-6649/com.example.bosutar_cosmin.nfc_writer D/dalvikvm﹕ VFY: replacing opcode 0x72 at 0x0002
10-08 19:35:35.016    6649-6649/com.example.bosutar_cosmin.nfc_writer I/dalvikvm﹕ Could not find method android.view.Window$Callback.onWindowStartingActionMode, referenced from method android.support.v7.internal.view.WindowCallbackWrapper.onWindowStartingActionMode
10-08 19:35:35.016    6649-6649/com.example.bosutar_cosmin.nfc_writer W/dalvikvm﹕ VFY: unable to resolve interface method 14080: Landroid/view/Window$Callback;.onWindowStartingActionMode (Landroid/view/ActionMode$Callback;I)Landroid/view/ActionMode;
10-08 19:35:35.016    6649-6649/com.example.bosutar_cosmin.nfc_writer D/dalvikvm﹕ VFY: replacing opcode 0x72 at 0x0002
10-08 19:35:35.090    6649-6649/com.example.bosutar_cosmin.nfc_writer I/dalvikvm﹕ Could not find method android.view.ViewGroup.onRtlPropertiesChanged, referenced from method android.support.v7.widget.Toolbar.onRtlPropertiesChanged
10-08 19:35:35.090    6649-6649/com.example.bosutar_cosmin.nfc_writer W/dalvikvm﹕ VFY: unable to resolve virtual method 13977: Landroid/view/ViewGroup;.onRtlPropertiesChanged (I)V
10-08 19:35:35.090    6649-6649/com.example.bosutar_cosmin.nfc_writer D/dalvikvm﹕ VFY: replacing opcode 0x6f at 0x0007
10-08 19:35:35.094    6649-6649/com.example.bosutar_cosmin.nfc_writer I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.internal.widget.TintTypedArray.getChangingConfigurations
10-08 19:35:35.095    6649-6649/com.example.bosutar_cosmin.nfc_writer W/dalvikvm﹕ VFY: unable to resolve virtual method 402: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
10-08 19:35:35.095    6649-6649/com.example.bosutar_cosmin.nfc_writer D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
10-08 19:35:35.096    6649-6649/com.example.bosutar_cosmin.nfc_writer I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.internal.widget.TintTypedArray.getType
10-08 19:35:35.096    6649-6649/com.example.bosutar_cosmin.nfc_writer W/dalvikvm﹕ VFY: unable to resolve virtual method 424: Landroid/content/res/TypedArray;.getType (I)I
10-08 19:35:35.096    6649-6649/com.example.bosutar_cosmin.nfc_writer D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
10-08 19:35:35.145    6649-6649/com.example.bosutar_cosmin.nfc_writer I/dalvikvm﹕ Could not find method android.content.res.Resources.getDrawable, referenced from method android.support.v7.internal.widget.ResourcesWrapper.getDrawable
10-08 19:35:35.146    6649-6649/com.example.bosutar_cosmin.nfc_writer W/dalvikvm﹕ VFY: unable to resolve virtual method 365: Landroid/content/res/Resources;.getDrawable (ILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable;
10-08 19:35:35.146    6649-6649/com.example.bosutar_cosmin.nfc_writer D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
10-08 19:35:35.147    6649-6649/com.example.bosutar_cosmin.nfc_writer I/dalvikvm﹕ Could not find method android.content.res.Resources.getDrawableForDensity, referenced from method android.support.v7.internal.widget.ResourcesWrapper.getDrawableForDensity
10-08 19:35:35.147    6649-6649/com.example.bosutar_cosmin.nfc_writer W/dalvikvm﹕ VFY: unable to resolve virtual method 367: Landroid/content/res/Resources;.getDrawableForDensity (IILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable;
10-08 19:35:35.147    6649-6649/com.example.bosutar_cosmin.nfc_writer D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
10-08 19:35:35.230    6649-6653/com.example.bosutar_cosmin.nfc_writer D/dalvikvm﹕ GC_CONCURRENT freed 216K, 4% free 8490K/8839K, paused 13ms+9ms, total 71ms
10-08 19:35:35.348    6649-6649/com.example.bosutar_cosmin.nfc_writer I/SurfaceTextureClient﹕ [void android::SurfaceTextureClient::init()] debug.stc.fps: 3000 ms
10-08 19:35:35.350    6649-6649/com.example.bosutar_cosmin.nfc_writer D/libEGL﹕ loaded /vendor/lib/egl/libEGL_mtk.so
10-08 19:35:35.354    6649-6649/com.example.bosutar_cosmin.nfc_writer D/libEGL﹕ loaded /vendor/lib/egl/libGLESv1_CM_mtk.so
10-08 19:35:35.358    6649-6649/com.example.bosutar_cosmin.nfc_writer D/libEGL﹕ loaded /vendor/lib/egl/libGLESv2_mtk.so
10-08 19:35:35.399    6649-6649/com.example.bosutar_cosmin.nfc_writer E/MMUMapper﹕ fail to register MVA, unsupported format(0x5)
10-08 19:35:35.401    6649-6649/com.example.bosutar_cosmin.nfc_writer D/OpenGLRenderer﹕ Enabling debug mode 0
10-08 19:35:35.513    6649-6649/com.example.bosutar_cosmin.nfc_writer E/MMUMapper﹕ fail to register MVA, unsupported format(0x5)
10-08 19:35:35.980    6649-6649/com.example.bosutar_cosmin.nfc_writer E/MMUMapper﹕ fail to register MVA, unsupported format(0x5)
10-08 19:35:38.963    6649-6649/com.example.bosutar_cosmin.nfc_writer I/SurfaceTextureClient﹕ [0x52024190] frames:8, duration:3.459000, fps:2.312427
10-08 19:35:41.970    6649-6649/com.example.bosutar_cosmin.nfc_writer I/SurfaceTextureClient﹕ [0x52024190] frames:6, duration:3.006000, fps:1.995360
10-08 19:35:42.058    6649-6649/com.example.bosutar_cosmin.nfc_writer D/VelocityTracker﹕ Couldn't open '/dev/touch' (No such file or directory)
10-08 19:35:42.058    6649-6649/com.example.bosutar_cosmin.nfc_writer D/VelocityTracker﹕ tpd read x fail: Bad file number
10-08 19:35:42.059    6649-6649/com.example.bosutar_cosmin.nfc_writer D/VelocityTracker﹕ tpd read y fail: Bad file number
10-08 19:35:44.980    6649-6649/com.example.bosutar_cosmin.nfc_writer I/SurfaceTextureClient﹕ [0x52024190] frames:10, duration:3.009000, fps:3.322367
10-08 19:35:45.885    6649-6649/com.example.bosutar_cosmin.nfc_writer E/writeCard :﹕ Transceive failed
10-08 19:35:45.923    6649-6649/com.example.bosutar_cosmin.nfc_writer I/SurfaceTextureClient﹕ [void android::SurfaceTextureClient::init()] debug.stc.fps: 3000 ms
10-08 19:35:45.939    6649-6649/com.example.bosutar_cosmin.nfc_writer E/MMUMapper﹕ fail to register MVA, unsupported format(0x1)
10-08 19:35:47.885    6649-6649/com.example.bosutar_cosmin.nfc_writer E/MMUMapper﹕ invalid operation for unregister MVA with VA(0x532fb000) size(98560)
10-08 19:35:47.920    6649-6649/com.example.bosutar_cosmin.nfc_writer I/SurfaceTextureClient﹕ [void android::SurfaceTextureClient::init()] debug.stc.fps: 3000 ms
10-08 19:35:47.937    6649-6649/com.example.bosutar_cosmin.nfc_writer E/MMUMapper﹕ fail to register MVA, unsupported format(0x1)
10-08 19:35:47.986    6649-6649/com.example.bosutar_cosmin.nfc_writer I/SurfaceTextureClient﹕ [0x52024190] frames:6, duration:3.006000, fps:1.995598
10-08 19:35:49.884    6649-6649/com.example.bosutar_cosmin.nfc_writer E/MMUMapper﹕ invalid operation for unregister MVA with VA(0x532fb000) size(88704)
10-08 19:35:49.933    6649-6649/com.example.bosutar_cosmin.nfc_writer I/SurfaceTextureClient﹕ [void android::SurfaceTextureClient::init()] debug.stc.fps: 3000 ms
10-08 19:35:49.950    6649-6649/com.example.bosutar_cosmin.nfc_writer E/MMUMapper﹕ fail to register MVA, unsupported format(0x1)
4

1 に答える 1

0

私が行ったすべての調査の後、互換性の問題があると結論付けました。

これは、NTAG21Xチップを搭載したNTAG216カードの読み取り/書き込みに成功し、私の知る限り、MIFARE S50チップを搭載したABK-1001MFカードの代替品として登場したためです。これは、私が最初に読み取り/書き込みを試みたカードです。 、同じタイプの電話LG Optimus L5 II E460を使用しています。

私の結論は、私が呼び出すときに次の事実によって強化されます。

getPackageManager().hasSystemFeature("com.nxp.mifare");

戻り値は false です。

助けてくれてありがとう!

于 2016-06-21T09:41:50.540 に答える