일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- deprecating the install_referrer
- Rx자바
- 하드코드검색
- Switch to the Play Referrer API by March 1
- RX
- android P
- hardcoded string search
- rxandroid
- Retrofit2
- 안드로이드
- RXjava
- Android
- RxJava2
- java
- andorid studio
Archives
- Today
- Total
Lucky Dog
[안드로이드] NFC 수신 본문
1. Activity 의 경우
1-1. manifest
<intent-filter> <action android:name="android.nfc.action.NDEF_DISCOVERED" /> <data android:mimeType="*/*" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> <intent-filter> <action android:name="android.nfc.action.TECH_DISCOVERED" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> <intent-filter> <action android:name="android.nfc.action.TAG_DISCOVERED" /> </intent-filter> <meta-data android:name="android.nfc.action.TECH_DISCOVERED" android:resource="@xml/nfc_tech_filter" /> |
1-2. xml file (nfc_tech_filter.xml)
<?xml version="1.0" encoding="utf-8"?> <resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> <tech-list> <tech>android.nfc.tech.IsoDep</tech> <tech>android.nfc.tech.NfcA</tech> <tech>android.nfc.tech.NfcB</tech> <tech>android.nfc.tech.NfcF</tech> <tech>android.nfc.tech.NfcV</tech> <tech>android.nfc.tech.Ndef</tech> <tech>android.nfc.tech.NdefFormatable</tech> <tech>android.nfc.tech.MifareClassic</tech> <tech>android.nfc.tech.MifareUltralight</tech> <tech>org.nfcforum.ndef.type2</tech> </tech-list> </resources> |
2. foreground에서 NFC 수신
2-1. onResume()
PendingIntent pIntent = PendingIntent.getActivity(this, 0, new Intent(this, getClass()), 0); // NFC filter 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_TECH_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[]{NfcA.class.getName(), NfcB.class.getName(), NfcF.class.getName(), NfcV.class.getName(), IsoDep.class.getName(), MifareClassic.class.getName(), MifareUltralight.class.getName(), Ndef.class.getName()}}; mNfcAdapter = NfcAdapter.getDefaultAdapter(this); mNfcAdapter.enableForegroundDispatch(this, pIntent, intentFilters, techLists); |
2-2. onpause()
mNfcAdapter.disableForegroundDispatch(this); |
Comments