Created
March 9, 2019 09:09
-
-
Save pratheepchowdhary/8d28ae9b3e9098deb2c24b282737229b 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
/** | |
* BroadcastReceiver to wait for SMS messages. This can be registered either | |
* in the AndroidManifest or at runtime. Should filter Intents on | |
* SmsRetriever.SMS_RETRIEVED_ACTION. | |
*/ | |
public class MySMSBroadcastReceiver extends BroadcastReceiver { | |
@Override | |
public void onReceive(Context context, Intent intent) { | |
if (SmsRetriever.SMS_RETRIEVED_ACTION.equals(intent.getAction())) { | |
Bundle extras = intent.getExtras(); | |
Status status = (Status) extras.get(SmsRetriever.EXTRA_STATUS); | |
switch(status.getStatusCode()) { | |
case CommonStatusCodes.SUCCESS: | |
// Get SMS message contents | |
String message = (String) extras.get(SmsRetriever.EXTRA_SMS_MESSAGE); | |
// Extract one-time code from the message and complete verification | |
// by sending the code back to your server. | |
break; | |
case CommonStatusCodes.TIMEOUT: | |
// Waiting for SMS timed out (5 minutes) | |
// Handle the error ... | |
break; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment