More Related Content
Similar to Host-based Card Emulation in touch (20)
Host-based Card Emulation in touch
- 29. 1. Service
class MyHostApduService : HostApduService() {
override fun processCommandApdu(commandApdu: ByteArray, extras: Bundle?): ByteArray {
if (Utils.isEqual(SELECT, commandApdu)) {
return "Hello, HCE!!".toByteArray()
}
return byteArrayOf(0x90.toByte(), 0x00)
}
override fun onDeactivated(reason: Int) {
}
……
- 30. 1. Service
class MyHostApduService : HostApduService() {
override fun processCommandApdu(commandApdu: ByteArray, extras: Bundle?): ByteArray {
if (Utils.isEqual(SELECT, commandApdu)) {
return "Hello, HCE!!".toByteArray()
}
return byteArrayOf(0x90.toByte(), 0x00)
}
override fun onDeactivated(reason: Int) {
}
……
- 31. 1. Service
class MyHostApduService : HostApduService() {
override fun processCommandApdu(commandApdu: ByteArray, extras: Bundle?): ByteArray {
if (Utils.isEqual(SELECT, commandApdu)) {
return "Hello, HCE!!".toByteArray()
}
return byteArrayOf(0x90.toByte(), 0x00)
}
override fun onDeactivated(reason: Int) {
}
……
- 32. 1. Service
class MyHostApduService : HostApduService() {
override fun processCommandApdu(commandApdu: ByteArray, extras: Bundle?): ByteArray {
if (Utils.isEqual(SELECT, commandApdu)) {
return "Hello, HCE!!".toByteArray()
}
return byteArrayOf(0x90.toByte(), 0x00)
}
override fun onDeactivated(reason: Int) {
}
……
- 33. 1. Service
class MyHostApduService : HostApduService() {
override fun processCommandApdu(commandApdu: ByteArray, extras: Bundle?): ByteArray {
if (Utils.isEqual(SELECT, commandApdu)) {
return "Hello, HCE!!".toByteArray()
}
return byteArrayOf(0x90.toByte(), 0x00)
}
override fun onDeactivated(reason: Int) {
}
……
- 34. 1. Service
class MyHostApduService : HostApduService() {
override fun processCommandApdu(commandApdu: ByteArray, extras: Bundle?): ByteArray {
if (Utils.isEqual(SELECT, commandApdu)) {
return "Hello, HCE!!".toByteArray()
}
doSomething()
return null
}
fun somethingHasDone() {
sendResponseApdu(byteArrayOf(0x90.toByte(), 0x00))
}
override fun onDeactivated(reason: Int) {
}
……
- 35. 1. Service
class MyHostApduService : HostApduService() {
override fun processCommandApdu(commandApdu: ByteArray, extras: Bundle?): ByteArray {
if (Utils.isEqual(SELECT, commandApdu)) {
return "Hello, HCE!!".toByteArray()
}
doSomething()
return null
}
fun somethingHasDone() {
sendResponseApdu(byteArrayOf(0x90.toByte(), 0x00))
}
override fun onDeactivated(reason: Int) {
}
……
- 36. 1. Service
class MyHostApduService : HostApduService() {
override fun processCommandApdu(commandApdu: ByteArray, extras: Bundle?): ByteArray {
if (Utils.isEqual(SELECT, commandApdu)) {
return "Hello, HCE!!".toByteArray()
}
return byteArrayOf(0x90.toByte(), 0x00)
}
override fun onDeactivated(reason: Int) {
}
……
- 38. permission
<uses-permission android:name=“android.permission.NFC"/>
<application … >
<service
android:name=“.MyHostApduService”
android:exported="true"
android:permission="android.permission.BIND_NFC_SERVICE">
<intent-filter>
<action android:name="android.nfc.cardemulation.action.HOST_APDU_SERVICE"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
<meta-data
android:name="android.nfc.cardemulation.host_apdu_service"
android:resource="@xml/apduservice"/>
</service>
</application>
- 39. service
<uses-permission android:name=“android.permission.NFC"/>
<application … >
<service
android:name=“.MyHostApduService”
android:exported="true"
android:permission="android.permission.BIND_NFC_SERVICE">
<intent-filter>
<action android:name="android.nfc.cardemulation.action.HOST_APDU_SERVICE"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
<meta-data
android:name="android.nfc.cardemulation.host_apdu_service"
android:resource="@xml/apduservice"/>
</service>
</application>
- 40. service
<uses-permission android:name=“android.permission.NFC"/>
<application … >
<service
android:name=“.MyHostApduService”
android:exported="true"
android:permission="android.permission.BIND_NFC_SERVICE">
<intent-filter>
<action android:name="android.nfc.cardemulation.action.HOST_APDU_SERVICE"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
<meta-data
android:name="android.nfc.cardemulation.host_apdu_service"
android:resource="@xml/apduservice"/>
</service>
</application>
- 41. intent-filter meta-data
<uses-permission android:name=“android.permission.NFC"/>
<application … >
<service
android:name=“.MyHostApduService”
android:exported="true"
android:permission="android.permission.BIND_NFC_SERVICE">
<intent-filter>
<action android:name="android.nfc.cardemulation.action.HOST_APDU_SERVICE"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
<meta-data
android:name="android.nfc.cardemulation.host_apdu_service"
android:resource="@xml/apduservice"/>
</service>
</application>
- 42. <uses-permission android:name=“android.permission.NFC"/>
<application … >
<service
android:name=“.MyHostApduService”
android:exported="true"
android:permission="android.permission.BIND_NFC_SERVICE">
<intent-filter>
<action android:name="android.nfc.cardemulation.action.HOST_APDU_SERVICE"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
<meta-data
android:name="android.nfc.cardemulation.host_apdu_service"
android:resource="@xml/apduservice"/>
</service>
</application>
- 43. intent-filter meta-data
<uses-permission android:name=“android.permission.NFC"/>
<application … >
<service
android:name=“.MyHostApduService”
android:exported="true"
android:permission="android.permission.BIND_NFC_SERVICE">
<intent-filter>
<action android:name="android.nfc.cardemulation.action.HOST_APDU_SERVICE"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
<meta-data
android:name="android.nfc.cardemulation.host_apdu_service"
android:resource="@xml/apduservice"/>
</service>
</application>
- 49. • NFC
• Tag Dispatch System
• Foreground Dispatch System
• NFC reader mode
- 50. • NFC
• Tag Dispatch System
• Foreground Dispatch System
• NFC reader mode
- 52. enableReaderMode
override fun onResume() {
super.onResume()
val adapter = NfcAdapter.getDefaultAdapter(context)
adapter.enableReaderMode(
context,
this,
NfcAdapter.FLAG_READER_NFC_A or NfcAdapter.FLAG_READER_SKIP_NDEF_CHECK,
null)
}
override fun onTagDiscovered(tag: Tag) {
val nfc = IsoDep.get(tag)
nfc.connect()
val res = nfc.transceive(SELECT)
Log.d(TAG, String(res, Charset.forName("UTF-8")))
}
- 53. enableReaderMode
override fun onResume() {
super.onResume()
val adapter = NfcAdapter.getDefaultAdapter(context)
adapter.enableReaderMode(
context,
this,
NfcAdapter.FLAG_READER_NFC_A or NfcAdapter.FLAG_READER_SKIP_NDEF_CHECK,
null)
}
override fun onTagDiscovered(tag: Tag) {
val nfc = IsoDep.get(tag)
nfc.connect()
val res = nfc.transceive(SELECT)
Log.d(TAG, String(res, Charset.forName("UTF-8")))
}
- 54. enableReaderMode
override fun onResume() {
super.onResume()
val adapter = NfcAdapter.getDefaultAdapter(context)
adapter.enableReaderMode(
context,
this,
NfcAdapter.FLAG_READER_NFC_A or NfcAdapter.FLAG_READER_SKIP_NDEF_CHECK,
null)
}
override fun onTagDiscovered(tag: Tag) {
val nfc = IsoDep.get(tag)
nfc.connect()
val res = nfc.transceive(SELECT)
Log.d(TAG, String(res, Charset.forName("UTF-8")))
}
- 55. enableReaderMode
override fun onResume() {
super.onResume()
val adapter = NfcAdapter.getDefaultAdapter(context)
adapter.enableReaderMode(
context,
this,
NfcAdapter.FLAG_READER_NFC_A or NfcAdapter.FLAG_READER_SKIP_NDEF_CHECK,
null)
}
override fun onTagDiscovered(tag: Tag) {
val nfc = IsoDep.get(tag)
nfc.connect()
val res = nfc.transceive(SELECT)
Log.d(TAG, String(res, Charset.forName("UTF-8")))
}
- 56. enableReaderMode
override fun onResume() {
super.onResume()
val adapter = NfcAdapter.getDefaultAdapter(context)
adapter.enableReaderMode(
context,
this,
NfcAdapter.FLAG_READER_NFC_A or NfcAdapter.FLAG_READER_SKIP_NDEF_CHECK,
null)
}
override fun onTagDiscovered(tag: Tag) {
val nfc = IsoDep.get(tag)
nfc.connect()
val res = nfc.transceive(SELECT)
Log.d(TAG, String(res, Charset.forName("UTF-8")))
}
- 57. enableReaderMode
override fun onResume() {
super.onResume()
val adapter = NfcAdapter.getDefaultAdapter(context)
adapter.enableReaderMode(
context,
this,
NfcAdapter.FLAG_READER_NFC_A or NfcAdapter.FLAG_READER_SKIP_NDEF_CHECK,
null)
}
override fun onTagDiscovered(tag: Tag) {
val nfc = IsoDep.get(tag)
nfc.connect()
val res = nfc.transceive(SELECT)
Log.d(TAG, String(res, Charset.forName("UTF-8")))
}
- 58. enableReaderMode
override fun onResume() {
super.onResume()
val adapter = NfcAdapter.getDefaultAdapter(context)
adapter.enableReaderMode(
context,
this,
NfcAdapter.FLAG_READER_NFC_A or NfcAdapter.FLAG_READER_SKIP_NDEF_CHECK,
null)
}
override fun onTagDiscovered(tag: Tag) {
val nfc = IsoDep.get(tag)
nfc.connect()
val res = nfc.transceive(SELECT)
Log.d(TAG, String(res, Charset.forName("UTF-8")))
}
- 59. SELECT
val SELECT = byteArrayOf(
0x00, 0xA4.toByte(), 0x04, 0x00,
0x07,
0xF0.toByte(), 0x39, 0x41, 0x48, 0x14, 0x81.toByte(), 0x00,
0x00
)
- 60. SELECT
val SELECT = byteArrayOf(
0x00, 0xA4.toByte(), 0x04, 0x00,
0x07,
0xF0.toByte(), 0x39, 0x41, 0x48, 0x14, 0x81.toByte(), 0x00,
0x00
)
- 61. SELECT
val SELECT = byteArrayOf(
0x00, 0xA4.toByte(), 0x04, 0x00,
0x07,
0xF0.toByte(), 0x39, 0x41, 0x48, 0x14, 0x81.toByte(), 0x00,
0x00
)
- 65. HCE-F
• Android7.0
• FeliCa
• SystemCode Idm
•
https://developer.android.com/reference/android/nfc/cardemulation/
NfcFCardEmulation.html#registerSystemCodeForService(android.content.ComponentName,%20java.lang.String)