Skip to content

Instantly share code, notes, and snippets.

@pjwelcome
Last active July 29, 2017 11:30
Show Gist options
  • Save pjwelcome/0a2278013b913568f43dd0d6aba3a3ce to your computer and use it in GitHub Desktop.
Save pjwelcome/0a2278013b913568f43dd0d6aba3a3ce to your computer and use it in GitHub Desktop.
class MainActivity : AppCompatActivity() {
private var mNfcAdapter: NfcAdapter? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
mNfcAdapter = NfcAdapter.getDefaultAdapter(this)
}
override fun onResume() {
super.onResume()
mNfcAdapter?.let {
NFCUtil.enableNFCInForeground(it, this,javaClass)
}
}
override fun onPause() {
super.onPause()
mNfcAdapter?.let {
NFCUtil.disableNFCInForeground(it,this)
}
}
override fun onNewIntent(intent: Intent?) {
super.onNewIntent(intent)
val messageWrittenSuccessfully = NFCUtil.createNFCMessage(messageEditText.text.toString(), intent)
resultTextView.text = ifElse(messageWrittenSuccessfully,"Successful Written to Tag","Something When wrong Try Again")
}
fun<T> ifElse(condition: Boolean, primaryResult: T, secondaryResult: T) = if (condition) primaryResult else secondaryResult
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment