![]() ![]() Register BroadcastReceiver in Android Manifest Next Section Then send the event to the listening subscriber. If this occurs, the timeout will be set to true. A timeout usually occurs if no messages have been received for 5 minutes. This is done if background processing was successful. The properties of this data class are set for the retrieved SMS message. If you’re completely new to EventBus, consider learning more about it here. The RetrievalEvent class will be a data class. This is the event class that EventBus will send to our Subscriber. We also construct an instance of the RetrievalEvent class. To handle this, let’s create a BroadcastReceiver class: In the onReceive() method, we first check the status of the SMS Retriever’s background processing. ![]() This intent keeps the SMS message and processing status in the background. This happens in case a device receives a message containing the code. Our API will pass a SmsRetriever.SMS RETRIEVED ACTION intent to the application. The above function is called in the onCreate() method. This is followed by invoking the initSmsRetriever instance function and adding onSuccessListener and onFailureListener to the task. Getting an instance of SmsRetriverClient Next Sectionįirst, we’ll get an instance of the SmsRetrieverClient. To perform SMS verification on a server, see SMS Verification on Server. This code will be extracted and displayed in the EditText that we added in activity_main.xml. Since I don’t have a verification server yet, we won’t be using this method in this article. Send it to your verification server, which should return the one-time code. In this step you should get the username phone EditText number. sending the mobile number for the server Next Section This edit text will display the one-time code obtained from our SMS message.Ĩ. Configure XML layout for our project Next Section We use it to communicate between our BroadcastReceiver and Activity classes.Īdd them to the adle file and sync the project: 7. EventBus is a library of publisher/subscriber patterns.
0 Comments
Leave a Reply. |