-
Notifications
You must be signed in to change notification settings - Fork 130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update AGP and JAVA Version to make it compatible with Gradle 8.7 and Add support for Streaming #179
Closed
Closed
Update AGP and JAVA Version to make it compatible with Gradle 8.7 and Add support for Streaming #179
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9b0d2a1
Update AGP version and Java compatibility
luckycreationsindia 716c7bd
Update AGP version and Java compatibility
luckycreationsindia 0292bcb
Update JavaVersion for Android app
luckycreationsindia c1ea7b0
Update Java version in GitHub workflow
luckycreationsindia fe10722
Update Android and Dart code to improve NFC functionality
luckycreationsindia a2ab10d
Update Gradle and Java versions
luckycreationsindia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
org.gradle.jvmargs=-Xmx1536M | ||
android.useAndroidX=true | ||
android.enableJetifier=true | ||
AGPVersion=7.4.2 | ||
AGPVersion=8.5.1 | ||
KotlinVersion=1.9.23 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
199 changes: 199 additions & 0 deletions
199
android/src/main/kotlin/im/nfc/flutter_nfc_kit/TagEventHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,199 @@ | ||
package im.nfc.flutter_nfc_kit | ||
|
||
import android.app.Activity | ||
import android.nfc.NfcAdapter | ||
import android.nfc.NfcAdapter.getDefaultAdapter | ||
import android.nfc.tech.IsoDep | ||
import android.nfc.tech.MifareClassic | ||
import android.nfc.tech.MifareUltralight | ||
import android.nfc.tech.Ndef | ||
import android.nfc.tech.NfcA | ||
import android.nfc.tech.NfcB | ||
import android.nfc.tech.NfcF | ||
import android.nfc.tech.NfcV | ||
import android.os.Handler | ||
import android.os.Looper | ||
import im.nfc.flutter_nfc_kit.ByteUtils.toHexString | ||
import im.nfc.flutter_nfc_kit.FlutterNfcKitPlugin.Companion.mifareInfo | ||
import im.nfc.flutter_nfc_kit.FlutterNfcKitPlugin.Companion.ndefTechnology | ||
import im.nfc.flutter_nfc_kit.FlutterNfcKitPlugin.Companion.tagTechnology | ||
import io.flutter.plugin.common.EventChannel | ||
import org.json.JSONObject | ||
import java.lang.ref.WeakReference | ||
|
||
|
||
class TagEventHandler(activity: WeakReference<Activity>) : EventChannel.StreamHandler { | ||
private var _activity: WeakReference<Activity> = activity | ||
private val nfcAdapter: NfcAdapter = getDefaultAdapter(_activity.get()) | ||
|
||
private val uiThreadHandler: Handler = Handler(Looper.getMainLooper()) | ||
|
||
override fun onListen(arguments: Any?, events: EventChannel.EventSink?) { | ||
val argsMap = arguments as? Map<*, *> | ||
val technologies = argsMap!!["technologies"] as Int | ||
|
||
val pollHandler = NfcAdapter.ReaderCallback { tag -> | ||
|
||
// common fields | ||
val type: String | ||
val id = tag.id.toHexString() | ||
val standard: String | ||
// ISO 14443 Type A | ||
var atqa = "" | ||
var sak = "" | ||
// ISO 14443 Type B | ||
var protocolInfo = "" | ||
var applicationData = "" | ||
// ISO 7816 | ||
var historicalBytes = "" | ||
var hiLayerResponse = "" | ||
// NFC-F / Felica | ||
var manufacturer = "" | ||
var systemCode = "" | ||
// NFC-V | ||
var dsfId = "" | ||
// NDEF | ||
var ndefAvailable = false | ||
var ndefWritable = false | ||
var ndefCanMakeReadOnly = false | ||
var ndefCapacity = 0 | ||
var ndefType = "" | ||
|
||
if (tag.techList.contains(NfcA::class.java.name)) { | ||
val aTag = NfcA.get(tag) | ||
atqa = aTag.atqa.toHexString() | ||
sak = byteArrayOf(aTag.sak.toByte()).toHexString() | ||
tagTechnology = aTag | ||
when { | ||
tag.techList.contains(IsoDep::class.java.name) -> { | ||
standard = "ISO 14443-4 (Type A)" | ||
type = "iso7816" | ||
val isoDep = IsoDep.get(tag) | ||
tagTechnology = isoDep | ||
historicalBytes = isoDep.historicalBytes.toHexString() | ||
} | ||
|
||
tag.techList.contains(MifareClassic::class.java.name) -> { | ||
standard = "ISO 14443-3 (Type A)" | ||
type = "mifare_classic" | ||
with(MifareClassic.get(tag)) { | ||
tagTechnology = this | ||
mifareInfo = MifareInfo( | ||
this.type, | ||
size, | ||
MifareClassic.BLOCK_SIZE, | ||
blockCount, | ||
sectorCount | ||
) | ||
} | ||
} | ||
|
||
tag.techList.contains(MifareUltralight::class.java.name) -> { | ||
standard = "ISO 14443-3 (Type A)" | ||
type = "mifare_ultralight" | ||
with(MifareUltralight.get(tag)) { | ||
tagTechnology = this | ||
mifareInfo = MifareInfo.fromUltralight(this.type) | ||
} | ||
} | ||
|
||
else -> { | ||
standard = "ISO 14443-3 (Type A)" | ||
type = "unknown" | ||
} | ||
} | ||
} else if (tag.techList.contains(NfcB::class.java.name)) { | ||
val bTag = NfcB.get(tag) | ||
protocolInfo = bTag.protocolInfo.toHexString() | ||
applicationData = bTag.applicationData.toHexString() | ||
if (tag.techList.contains(IsoDep::class.java.name)) { | ||
type = "iso7816" | ||
standard = "ISO 14443-4 (Type B)" | ||
val isoDep = IsoDep.get(tag) | ||
tagTechnology = isoDep | ||
hiLayerResponse = isoDep.hiLayerResponse.toHexString() | ||
} else { | ||
type = "unknown" | ||
standard = "ISO 14443-3 (Type B)" | ||
tagTechnology = bTag | ||
} | ||
} else if (tag.techList.contains(NfcF::class.java.name)) { | ||
standard = "ISO 18092 (FeliCa)" | ||
type = "iso18092" | ||
val fTag = NfcF.get(tag) | ||
manufacturer = fTag.manufacturer.toHexString() | ||
systemCode = fTag.systemCode.toHexString() | ||
tagTechnology = fTag | ||
} else if (tag.techList.contains(NfcV::class.java.name)) { | ||
standard = "ISO 15693" | ||
type = "iso15693" | ||
val vTag = NfcV.get(tag) | ||
dsfId = vTag.dsfId.toHexString() | ||
tagTechnology = vTag | ||
} else { | ||
type = "unknown" | ||
standard = "unknown" | ||
} | ||
|
||
// detect ndef | ||
if (tag.techList.contains(Ndef::class.java.name)) { | ||
val ndefTag = Ndef.get(tag) | ||
ndefTechnology = ndefTag | ||
ndefAvailable = true | ||
ndefType = ndefTag.type | ||
ndefWritable = ndefTag.isWritable | ||
ndefCanMakeReadOnly = ndefTag.canMakeReadOnly() | ||
ndefCapacity = ndefTag.maxSize | ||
} | ||
|
||
val jsonResult = JSONObject( | ||
mapOf( | ||
"type" to type, | ||
"id" to id, | ||
"standard" to standard, | ||
"atqa" to atqa, | ||
"sak" to sak, | ||
"historicalBytes" to historicalBytes, | ||
"protocolInfo" to protocolInfo, | ||
"applicationData" to applicationData, | ||
"hiLayerResponse" to hiLayerResponse, | ||
"manufacturer" to manufacturer, | ||
"systemCode" to systemCode, | ||
"dsfId" to dsfId, | ||
"ndefAvailable" to ndefAvailable, | ||
"ndefType" to ndefType, | ||
"ndefWritable" to ndefWritable, | ||
"ndefCanMakeReadOnly" to ndefCanMakeReadOnly, | ||
"ndefCapacity" to ndefCapacity, | ||
) | ||
) | ||
|
||
if (mifareInfo != null) { | ||
with(mifareInfo!!) { | ||
jsonResult.put( | ||
"mifareInfo", JSONObject( | ||
mapOf( | ||
"type" to typeStr, | ||
"size" to size, | ||
"blockSize" to blockSize, | ||
"blockCount" to blockCount, | ||
"sectorCount" to sectorCount | ||
) | ||
) | ||
) | ||
} | ||
} | ||
|
||
uiThreadHandler.post { | ||
events?.success(jsonResult.toString()) | ||
} | ||
} | ||
|
||
nfcAdapter.enableReaderMode(_activity.get(), pollHandler, technologies, null) | ||
} | ||
|
||
override fun onCancel(p0: Any?) { | ||
nfcAdapter.disableReaderMode(_activity.get()) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
org.gradle.jvmargs=-Xmx1536M | ||
android.useAndroidX=true | ||
android.enableJetifier=true | ||
AGPVersion=7.4.2 | ||
AGPVersion=8.5.1 | ||
KotlinVersion=1.9.23 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't downgrade this again, as it will cause breakage downstream.
See: #127 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll give an update soon. Problem is I'm getting issue like Java Version 21 and Kotlin Version 17. I tried fixing it but the error didn't compile. Maybe I need to clean everything and try again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed the version back to 17 and it's working but automated checks are failing. I can build the app without issues but here Github Actions are failing without proper error.