Skip to content

Instantly share code, notes, and snippets.

@pjwelcome
Created July 29, 2017 11:15
Show Gist options
  • Save pjwelcome/401ee89a50df2b428a023dcc24f70be7 to your computer and use it in GitHub Desktop.
Save pjwelcome/401ee89a50df2b428a023dcc24f70be7 to your computer and use it in GitHub Desktop.
fun <T>enableNFCInForeground(nfcAdapter: NfcAdapter, activity: Activity, classType : Class<T>) {
val pendingIntent = PendingIntent.getActivity(activity, 0,
Intent(activity,classType).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0)
val nfcIntentFilter = IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED)
val filters = arrayOf(nfcIntentFilter)
val TechLists = arrayOf(arrayOf(Ndef::class.java.name), arrayOf(NdefFormatable::class.java.name))
nfcAdapter.enableForegroundDispatch(activity, pendingIntent, filters, TechLists)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment