Lucky Dog

[안드로이드] NFC fillter prommatically 본문

안드로이드

[안드로이드] NFC fillter prommatically

Poohya 2015. 7. 15. 16:41
        IntentFilter intentFilter_1 = new IntentFilter();
        intentFilter_1.addAction(NfcAdapter.ACTION_NDEF_DISCOVERED);
        try {
            intentFilter_1.addDataType("*/*");
        } catch (MalformedMimeTypeException e) {
            e.printStackTrace();
        }
 
        IntentFilter intentFilter_2 = new IntentFilter();
        intentFilter_2.addAction(NfcAdapter.ACTION_TECH_DISCOVERED);
        try {
            intentFilter_2.addDataType("*/*");
        } catch (MalformedMimeTypeException e) {
            e.printStackTrace();
        }
 
        IntentFilter intentFilter_3 = new IntentFilter();
        intentFilter_3.addAction(NfcAdapter.ACTION_TAG_DISCOVERED);
        try {
            intentFilter_3.addDataType("*/*");
        } catch (MalformedMimeTypeException e) {
            e.printStackTrace();
        }
 
        IntentFilter[] intentFilters = new IntentFilter[]{intentFilter_1,
                intentFilter_2, intentFilter_3};
 
        String[][] techLists = new String[][]{
                new String[]{MifareUltralight.class.getName(), Ndef.class.getName(),
                        NfcA.class.getName(), NfcB.class.getName(), NfcF.class.getName(),
                        NfcV.class.getName(), IsoDep.class.getName(),
                        NdefFormatable.class.getName()},
                new String[]{MifareClassic.class.getName(), Ndef.class.getName(),
                        NfcA.class.getName(), NfcB.class.getName(), NfcF.class.getName(),
                        NfcV.class.getName(), IsoDep.class.getName(),
                        NdefFormatable.class.getName()}
        };
 
        mNfcAdapter.enableForegroundDispatch(this, pIntent, intentFilters,
                techLists);
        registerReceiver(mNFCReceiver, intentFilter);


Comments