Перейти к публикации

Winsoft Nfcnet Library For Android V10 New

On Android 10+, apps often lose focus or get paused. To ensure your app catches the NFC tag even when it is open (Foreground Dispatch), WinSoft handles much of this internally, but you must ensure your app handles the Intent properly.

In older versions of the library, you might have needed to hook into MainActivity lifecycle events. In the newest versions of NFCNET, setting Active := True usually handles the foreground dispatch registration automatically.

However, if your app crashes or fails to scan after the screen rotates or goes to sleep:

This ensures the NFC adapter re-registers the intent filter when the user returns to your app. winsoft nfcnet library for android v10 new

NFCNet provides its own HCE service to bypass some limitations.

One of the killer features of the v10 release is the automated MIFARE Classic key search. In older versions, you had to supply known keys. Version 10 includes a built-in "Key Finder" that can crack a MIFARE Classic 1K sector in under 3 seconds using a dictionary of 100 common keys.

// Authenticate sector 5 with default key
val sector = mifareClassicTag.getSector(5)
val authResult = sector.authenticate(KeyType.A, "FFFFFFFFFFFF".hexToByteArray())

if (authResult.success) val blockData = sector.readBlock(21) // Read specific block Log.i("NFC", "Data: $blockData.toHexString()") else // Auto-key finder fallback val foundKey = nfcManager.keyFinder.findKey(mifareClassicTag, sector.id) sector.authenticate(KeyType.A, foundKey) On Android 10+, apps often lose focus or get paused

| Android Version | Built-in NFC | USB Readers | Background Mode | |----------------|--------------|-------------|------------------| | 10 (Q) | Full | Full | Yes (with location) | | 11 (R) | Full | Full | Yes | | 12 (S) | Full | Full | Yes | | 13 (Tiramisu) | Full | Full | Yes | | 14 (UpsideDownCake) | Full | Full | Yes |

The library also maintains partial support back to Android 7.0 (Nougat), but the v10 new variant is optimized for Android 10+. This ensures the NFC adapter re-registers the intent

Let’s demonstrate the power of the new version. Below is a complete Kotlin snippet using the new asynchronous engine:

class MainActivity : AppCompatActivity() 
    private lateinit var nfcManager: NfcNetManager
override fun onCreate(savedInstanceState: Bundle?) 
    super.onCreate(savedInstanceState)
// Initialize with lifecycle scope
    nfcManager = NfcNetManager.Builder(this)
        .setLogging(true)
        .setAsyncMode(true)
        .build()
override fun onResume() 
    super.onResume()
    nfcManager.enableDispatch  tagResult ->
        when (tagResult) 
            is NfcTagFound -> 
                // Read UID and technology
                val uid = tagResult.tag.uid
                val tech = tagResult.tag.technologies
// Read NDEF message if available
                val ndef = tagResult.tag.getNdefMessage()
                runOnUiThread 
                    textView.text = "Tag UID: $uid\nNDEF: $ndef?.records?.firstOrNull()?.text"
is NfcError -> Log.e("NFC", "Error: $tagResult.throwable.message")
override fun onPause() 
    super.onPause()
    nfcManager.disableDispatch()

Notice there are no intent filters, no PendingIntent management, and no onNewIntent overrides. The library handles the Android lifecycle for you.

The library boasts a rewritten APDU processing engine. It now supports high-level T=CL and T=1 protocols with precise timing control. For developers working with Java Cards or national eID cards, this means faster, more reliable command-response pairs.

×
×
  • Создать...