Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/10102004tan/broadcast-receiver-sms


https://github.com/10102004tan/broadcast-receiver-sms

Last synced: 5 days ago
JSON representation

Awesome Lists containing this project

README

        

Project broadcast receiver


Libraries:



  • implementation ("com.google.android.gms:play-services-auth:19.0.0")

  • implementation ("com.google.android.gms:play-services-auth-api-phone:17.5.0")


How to register broadcast Receiver





private void registerBroadcastReceiver(){
broadcastReceiver = new SmsBroadcastReceiver();
broadcastReceiver.smsBroadcastReceiverListener = new SmsBroadcastReceiver.SmsBroadcastReceiverListener() {
@Override
public void onSuccess(Intent intent) {
startActivityForResult(intent,REQ_USER_CONSENT);
}
@Override
public void onFailure() {
}
};
IntentFilter intentFilter = new IntentFilter(SmsRetriever.SMS_RETRIEVED_ACTION);
this.registerReceiver(broadcastReceiver,intentFilter,RECEIVER_EXPORTED);}


Why use RECEIVER_EXPORTED , u can read : https://stackoverflow.com/questions/77235063/one-of-receiver-exported-or-receiver-not-exported-should-be-specified-when-a-rec




How to show dialog bottom when have otp


Create method startSmartUserConsent in Activity



private void startSmartUserConsent() {
SmsRetrieverClient client = SmsRetriever.getClient(this);
client.startSmsUserConsent(null);
}


How to get otp



private void getOtpFromMessage(String message) {
Pattern otpPattern = Pattern.compile("(|^)\\d{6}");
Matcher matcher = otpPattern.matcher(message);
if (matcher.find()){
otp.setText(matcher.group(0));
}
}