Joke Collection Website - Blessing messages - Why does someone else's Xiaomi mobile phone automatically fill in the verification code when it is received, but mine doesn't?
Why does someone else's Xiaomi mobile phone automatically fill in the verification code when it is received, but mine doesn't?
Auto-filling is the function of some software, not the function of mobile phone. For example, Alipay can automatically fill in the verification code in the short message in some places where the verification code is entered, provided that your mobile phone has opened the permission to read the short message to Alipay, otherwise Alipay can't get the content of your short message.
In the process of application development, we need to send a verification code to the user to verify the user's identity, but after receiving the SMS verification code, the user needs to leave the current application to check the verification code, and then return to our application to fill in the verification code, which will bring a lot of inconvenience to the user. Applications on android system can read short messages on mobile phones, and we can use this function to get what we want and display it in our input box.
The function we implemented this time needs ContentObserver. When we send a short message to our mobile phone, the mobile phone will automatically call the method specified in the ContentObserver class to inform our application of the changes in the content of the short message. We extract the information from the content and fill it in our input box?
Here I tell you a related design pattern: observer pattern:
Observer pattern is a software design pattern. In this mode, the target object manages all the observer objects that depend on it, and actively sends out notifications when its own state changes. This is usually done by calling the method provided by the observer. This mode is usually used to implement a time processing system.
Observer pattern perfectly separates the observer from the observed object, delimits clear boundaries between modules, and improves the maintainability and reusability of the application.
The observer design pattern defines the one-to-many dependency between objects, so that when the state of an object changes, all the objects that depend on it will be notified and refreshed automatically.
Applied to our example, we first register an observer with our system SMS application during the initial operation of the application, and tell our SMS application that I am your observer, and you will inform me when your own status changes.
Let's look at the basic flow of the observer:
The observer registers himself in the observed subject, and the observed subject stores the observer in the container.
When the observed object changes, all registered observers are obtained from the container, and the changes are notified to the observers.
The observer tells the observer to cancel the observation, and the observer removes the observer from the container.
The purpose of the content observer is to observe (capture) the changes caused by specific URIs in the database, and then do some corresponding processing. It is similar to the trigger in database technology, and it will be triggered when the Uri observed by Content Server changes.
To observe a specific Uri, follow these steps:
1. In order to create our specific ContentOberver derived class, we must overload the parent class constructor and onChange () method to handle the function implementation after the callback.
2. Use context.getContetResolover () to get the ContentResolover object, and then call the registerContentObeserver () method to register the content observer.
3. Because the life cycle of ContentObserver is out of sync with activities and services, it is necessary to manually call unregisterContentObserver () to cancel registration when it is not needed.
- Previous article:Taiyuan SF Express Customer Service Phone
- Next article:Ask for a word of praise and thanks.
- Related articles
- The bank SMS reminded that the credit card application was successful. Did you pass?
- How to get the marathon invitation code?
- What if I forget my registration serial number and password?
- Congratulations on your colleague's marriage, humorous blessing message.
- Did you send a text message after the successful driver's license appointment?
- Dragon Boat Festival greetings to lovers
- What birthday wishes do you have for your son 10 birthday?
- 2022 short and warm words, New Year greeting copy
- What are the benefits of Yantai Mobile's business card?
- How to make the font of short messages bigger?