Last active
July 29, 2017 11:30
-
-
Save pjwelcome/0a2278013b913568f43dd0d6aba3a3ce to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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