Last active
December 22, 2020 18:04
-
-
Save shikto1/839c6cb5244f56d0e580a1f610a73844 to your computer and use it in GitHub Desktop.
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
class MainActivity : AppCompatActivity() { | |
private var intentFilter: IntentFilter? = null | |
private var smsReceiver: SMSReceiver? = null | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
initBroadCast() | |
} | |
private fun initBroadCast() { | |
intentFilter = IntentFilter(SmsRetriever.SMS_RETRIEVED_ACTION) | |
smsReceiver = SMSReceiver() | |
smsReceiver?.setOTPListener(object : OTPReceiveListener { | |
override fun onOTPReceived(otp: String?) { | |
showToast("OTP Received: $otp") | |
} | |
}) | |
} | |
override fun onResume() { | |
super.onResume() | |
registerReceiver(smsReceiver, intentFilter) | |
} | |
override fun onPause() { | |
super.onPause() | |
unregisterReceiver(smsReceiver) | |
} | |
private fun showToast(msg: String?) { | |
Toast.makeText(this, msg, Toast.LENGTH_SHORT).show() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment