diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 07c363d..7f7b9da 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -21,17 +21,9 @@
-
-
-
-
-
-
-
diff --git a/app/src/main/java/com/example/palto/MainActivity.kt b/app/src/main/java/com/example/palto/MainActivity.kt
index 630cbee..7936f6c 100644
--- a/app/src/main/java/com/example/palto/MainActivity.kt
+++ b/app/src/main/java/com/example/palto/MainActivity.kt
@@ -5,6 +5,9 @@ import android.content.Intent
import android.content.IntentFilter
import android.nfc.NfcAdapter
import android.nfc.Tag
+import android.nfc.tech.IsoDep
+import android.nfc.tech.NdefFormatable
+import android.nfc.tech.NfcA
import android.os.Build
import android.os.Bundle
import android.util.Log
@@ -32,70 +35,28 @@ class MainActivity : AppCompatActivity() {
if (!(this.nfcAdapter!!.isEnabled)) {
Log.w("NFC", "NFC is not enabled")
}
-
- // check if the application was started by an intent
- if (this.intent != null) this.processIntent(intent)
}
override fun onResume() {
super.onResume()
- val intent = Intent(
+ nfcAdapter!!.enableReaderMode(
this,
- this::class.java
+ this::processTag,
+ NfcAdapter.FLAG_READER_NFC_A or NfcAdapter.FLAG_READER_SKIP_NDEF_CHECK,
+ null
)
- intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING)
-
- val pendingIntent = PendingIntent.getActivity(this, 0, intent, 0)
- val intentFilter = arrayOf()
-
- // enable the NFC discovery
- nfcAdapter?.enableForegroundDispatch(this, pendingIntent, intentFilter, null)
}
override fun onPause() {
super.onPause()
// disable the NFC discovery
- this.nfcAdapter!!.disableForegroundDispatch(this)
+ this.nfcAdapter!!.disableReaderMode(this)
}
- override fun onNewIntent(intent: Intent?) {
- super.onNewIntent(intent)
-
- // check the new intent
- if (intent != null) {
- this.processIntent(intent)
- }
- }
-
- private fun processIntent(intent: Intent) {
- Log.d("NFC", "New : ${intent.action}")
-
- var text: TextView = this.findViewById(R.id.test_text)
- text.text = intent.action
-
- if (intent.action == NfcAdapter.ACTION_TAG_DISCOVERED) {
- val tag: Tag? = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
- intent.getParcelableExtra(NfcAdapter.EXTRA_TAG, Tag::class.java)
- } else {
- intent.getParcelableExtra(NfcAdapter.EXTRA_TAG)
- }
-
- Log.d("NFC", "Tag : ${tag?.id.contentToString()}")
- }
-
- if (intent.action == NfcAdapter.ACTION_TECH_DISCOVERED) { // TODO(Faraphel): switch ?
-
- val tag: Tag? = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
- intent.getParcelableExtra(NfcAdapter.EXTRA_TAG, Tag::class.java)
- } else {
- intent.getParcelableExtra(NfcAdapter.EXTRA_TAG)
- }
-
- Log.d("NFC", "Tag : $tag")
-
- }
-
+ @OptIn(ExperimentalStdlibApi::class)
+ fun processTag(tag: Tag) {
+ Log.d("NFC", "Tag ID : ${tag.id.toHexString()}")
}
}
diff --git a/app/src/main/res/xml/nfc_tech_filter.xml b/app/src/main/res/xml/nfc_tech_filter.xml
deleted file mode 100644
index 421d405..0000000
--- a/app/src/main/res/xml/nfc_tech_filter.xml
+++ /dev/null
@@ -1,7 +0,0 @@
-
-
- android.nfc.tech.IsoDep
- android.nfc.tech.NfcA
- android.nfc.tech.NdefFormatable
-
-