-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
56 changed files
with
1,605 additions
and
1,044 deletions.
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
86 changes: 86 additions & 0 deletions
86
android/app/src/main/kotlin/com/osj/lotura/MainActivity.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,86 @@ | ||
package com.osj.lotura | ||
|
||
import android.app.PendingIntent | ||
import android.content.Intent | ||
import android.content.IntentFilter | ||
import android.nfc.NdefMessage | ||
import android.nfc.NdefRecord | ||
import android.nfc.NfcAdapter | ||
import android.os.Bundle | ||
import io.flutter.embedding.android.FlutterActivity | ||
import io.flutter.embedding.engine.FlutterEngine | ||
import io.flutter.plugin.common.MethodChannel | ||
|
||
class MainActivity : FlutterActivity() { | ||
private lateinit var nfcAdapter: NfcAdapter | ||
private var returnData = -1 | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
nfcAdapter = NfcAdapter.getDefaultAdapter(this) | ||
|
||
if (intent.action == NfcAdapter.ACTION_NDEF_DISCOVERED) { | ||
val data = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES) | ||
val message = data?.get(0) as NdefMessage | ||
val record = message.records[0] as NdefRecord | ||
val byteArr = record.payload | ||
|
||
returnData = String(byteArr).toInt() | ||
} | ||
} | ||
|
||
override fun configureFlutterEngine(flutterEngine: FlutterEngine) { | ||
super.configureFlutterEngine(flutterEngine) | ||
MethodChannel( | ||
flutterEngine.dartExecutor.binaryMessenger, | ||
"com.osj.lotura/nfc_info" | ||
).setMethodCallHandler { call, result -> | ||
when (call.method) { | ||
"getNFCInfo" -> { | ||
result.success("{\"index\" : $returnData}") | ||
returnData = -1 | ||
} | ||
|
||
"nfcIsAvailable" -> { | ||
result.success(nfcAdapter.isEnabled) | ||
} | ||
} | ||
} | ||
} | ||
|
||
override fun onNewIntent(intent: Intent) { | ||
super.onNewIntent(intent) | ||
if (intent.action == NfcAdapter.ACTION_NDEF_DISCOVERED) { | ||
val data = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES) | ||
val message = data?.get(0) as NdefMessage | ||
val record = message.records[0] as NdefRecord | ||
val byteArr = record.payload | ||
|
||
returnData = String(byteArr).toInt() | ||
} | ||
} | ||
|
||
override fun onResume() { | ||
super.onResume() | ||
enableNfcForegroundDispatch() | ||
} | ||
|
||
override fun onPause() { | ||
super.onPause() | ||
disableNfcForegroundDispatch() | ||
} | ||
|
||
private fun enableNfcForegroundDispatch() { | ||
val pendingIntent = PendingIntent.getActivity( | ||
this, 0, Intent(this, javaClass).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), | ||
PendingIntent.FLAG_IMMUTABLE | ||
) | ||
val intentFilters = arrayOf( | ||
IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED), | ||
) | ||
nfcAdapter.enableForegroundDispatch(this, pendingIntent, intentFilters, null) | ||
} | ||
|
||
private fun disableNfcForegroundDispatch() { | ||
nfcAdapter.disableForegroundDispatch(this) | ||
} | ||
} |
6 changes: 0 additions & 6 deletions
6
android/app/src/main/kotlin/com/team/osj/lotura/MainActivity.kt
This file was deleted.
Oops, something went wrong.
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
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
Oops, something went wrong.