Joke Collection Website - Public benefit messages - How to use MOB's UI-free SMS SDK
How to use MOB's UI-free SMS SDK
1. I chose Mob SMS verification code SDK because it is completely free, so it is very suitable for my own test or personal small project. However, it is a bit pitted that there is a limit on the number of times before each mobile phone number goes online, and the content of short messages cannot be customized. 2. First open Mob official website and download SDK3. Unzip the downloaded. Zip file, its file structure is shown as follows: 4. Open official website, log in to your account, and choose to enter the background. 5. Select the security code K6. 6. apply for APPKey and AppSecret, and apply for 7. 7. Create a project mydemo that we want to test ourselves and import the dependency library, which is three steps: the first step is to open the file downloaded in 3. Then import the SMSSDK from your own project into the project (note that when other projects in eclipse also contain SMSSDK, it may not be imported, so this situation should be avoided) 9. Step 3: Right-click the project again and select properties-& gt;; Android-& gt; Add-> SMSSDK-& gt; Ok 10。 Well, all the preparations have been made. Next, write the code (1) SMS SDK. init SDK (this," 1 1b 137E3A500 "," 632F0C9cf 1cd6838 "。 //Initialize //sdk before use, and the second parameter, that is, key and secret in 6/* * * (2) write short messages to send and monitor, and judge whether the verification code is sent or not, whether the submitted verification code passes or not, and so on. Because this is not in the main thread, the UI thread cannot operate. Therefore, the message mechanism */Eventhandler eh = NewEventhandler () {PublicFoidateEvent (intarg0, intarg 1, ObjectArg2) {//AfterEvent is the method of calling back after calling SDK: messagem = message.obtain (); m . what = 1; m . arg 1 = arg 0; //eventm . arg 2 = arg 1; //result handler . sendmessage(m); }}; (3)smssdk . registereventhandler(eh); //Register SMS callback interface (4)/* * Add a button, and click it to send SMS. Note that only when the current network is online can you access the server to obtain the verification code. The method CommonUtils.getNetworkInfo is a user-defined tool for judging the network state, which is very simple */publicvidsphonereregister (context context, stringstr) {this. Context = context; if(common utils . getnetworkinfo(context)! = 2){ SMS SDK . getverificationcode(" 86 ",str); //Requesting to get the SMS verification code, the EvenHandler interface returns during the listening process, str: mobile phone number }else{Toast.makeText(context, "Please check the network connection", Toast. LENGTH_SHORT)。 show(); }} (5)/* * Add the submit button verification code */PublicVidscommitmv (context context, stringstr, stringstr 1) {SMS SDK. Submission code ("86", STR, str1); //Submit SMS verification code, and return when monitoring. Str: mobile phone number str 1: verification code received} (6)/* * Receiving message */Handlerhandler = NewHandler () {Publicfoidhadmessage (message msg) {switch (msg.what) in afterevent method. { case 1:if(msg . arg 2 = = SMS SDK。 result _ complete){//If(msg . arg 1 = = SMS SDK。 Event _ submit _ verification _ code) successfully sent {//The verification passed intenti = new intent (context 2). context 2 . start activity(I); } else if (msg.arg 1 = = SMS SDK。 Event _ get _ verification _ code) {//The verification code has been sent from the server to Toast.makeText(context, "Verification code has been sent, please check", Toast. LENGTH_SHORT)。 show(); }}else{Toast.makeText (context, "verification code error", Toast. LENGTH_SHORT)。 show(); } broken; }}; }; (7) PublicFoIdUnregisterEventHandler () {//Finally log off listening, otherwise it may cause memory leakage SMS SDK. unregister eventhandler(eh); }(8) Finally, don't forget to add permissions and an activity. This activity place is the same as ordinary activities. (9)/* * MOB official documentation shows that *getVerificationCode is used to request the service of sending verification code to the server, and it needs to pass the country code and the mobile phone number to receive verification code. The country codes that support this service can be obtained from getSupportedCountries. * The time interval for requesting getVerificationCode should not be less than 60 seconds, otherwise the server will return an error of "Too frequent operation" * SubmittationCode is used to submit the received SMS verification code to the server, and return the country code and telephone number through EventHandler after successful verification. */
- Related articles
- How can Huawei set up a SMS center if it can't send SMS?
- What does it mean that the shepherd boy has no excuse to play piccolo?
- How to get the password of mobile phone service through SMS?
- How to register a WeChat account with a mobile phone number?
- Will it affect if the SMS notification of bank card is not closed and there is no money in the card?
- Warm love sends a sentence?
- Find a spoof message about engagement.
- How to check the received information records when inquiring the call records?
- New Year's greetings for 2022 Year of the Tiger
- I received a violation message but there was no specific violation, and the APP could not find it.