How to fix SMS retriever API | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to fix SMS retriever API

I used this post https://developers.google.com/identity/sms-retriever/request This code past to MySMSBroadcastReceiver. 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) extras.get(SmsRetriever.EXTRA_STATUS); switch(status.getStatusCode()) { case CommonStatusCodes.SUCCESS: message = (String) extras.get(SmsRetriever.EXTRA_SMS_MESSAGE); break; case CommonStatusCodes.TIMEOUT: break; } mListener.MySMSBroadcastReceiver(message); } } public static void bindListener(MessageListener listener){ mListener = listener; }} But result get nothing. Help what do I do wrong?

8th Sep 2019, 6:38 AM
Иван Кордяк
Иван Кордяк - avatar
6 Answers
0
can you use variables status and message without declaration ? Status status = String message =
8th Sep 2019, 1:19 PM
zemiak
0
I use variables status, message. I don't do what working sms broadcast receiver
9th Sep 2019, 1:20 PM
Иван Кордяк
Иван Кордяк - avatar
0
. you deleted types of this variables, I asked why? . have you Android devices with Play services version 10.2 and newer. ?, is required
10th Sep 2019, 4:31 AM
zemiak
0
I didn't delete this variables, they didnt fit in post. Yes, 10 and newer.
10th Sep 2019, 5:11 AM
Иван Кордяк
Иван Кордяк - avatar
0
I wanted to add an example, but I lost the connection, I just see these differences in the code, but so obviously you know about it. ok //Status status = (Status) extras.get(SmsRetriever.EXTRA_STATUS); //original status = (Status) extras.get(SmsRetriever.EXTRA_STATUS); //your code //String message = (String) extras.get(SmsRetriever.EXTRA_SMS_MESSAGE); //original message = (String) extras.get(SmsRetriever.EXTRA_SMS_MESSAGE); //your code
10th Sep 2019, 7:21 AM
zemiak
0
Yes, before all code I wrote variables: Status status; String message;
11th Sep 2019, 2:07 AM
Иван Кордяк
Иван Кордяк - avatar