Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/10102004tan/broadcast-receiver-sms
https://github.com/10102004tan/broadcast-receiver-sms
Last synced: 5 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/10102004tan/broadcast-receiver-sms
- Owner: 10102004tan
- Created: 2024-04-25T16:43:58.000Z (7 months ago)
- Default Branch: master
- Last Pushed: 2024-04-25T16:53:40.000Z (7 months ago)
- Last Synced: 2024-04-25T17:51:26.297Z (7 months ago)
- Language: Java
- Size: 101 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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));
}
}