Android extension uses Bmob backend cloud to implement SMS verification code

Source: Internet
Author: User

Bmob back-end cloud, this is not what I said, it is very important in our Android development process. Specifically what services can be bmob the official website to inquire

about how to implement the method of SMS verification code, in fact, Bmob in the back end of the cloud has been introduced in detail. The main thing I'm here for is to share my experience.

1. To implement SMS verification code, you must download the SDK for SMS verification code on Bmob's official website, and then import the project

2. Using the SDK, this SDK can be used alone and can be initialized directly. What is the use alone? is to initialize the SDK directly and use it without initializing the Bmob

A. How to initialize Bmob?

By calling Bmob.initialize (this, "Your App id"); (first to download the SDK for data services on Bmob, import the project)

B. How do I initialize the SDK for SMS verification code?

By calling Bmobsms.initialize (this, "Your App id");

Now I'm just going to post my code.

1,androidmanifest Permissions Configuration

1 <!--Allow networking -2 <uses-permissionAndroid:name= "Android.permission.INTERNET" />3 <!--Get information on network status such as GSM (2g), WCDMA (Unicom 3g), etc. -4 <uses-permissionAndroid:name= "Android.permission.ACCESS_NETWORK_STATE" />5 <!--get information about the status of your WiFi network -6 <uses-permissionAndroid:name= "Android.permission.ACCESS_WIFI_STATE" />

2.MainActivity Code

Java code

1  PackageCom.example.android_message;2 3 Importcom.example.regist.RegistActivity;4 5 Importandroid.app.Activity;6 Importandroid.content.Intent;7 Importandroid.graphics.Region;8 ImportAndroid.os.Bundle;9 ImportAndroid.view.View;Ten ImportAndroid.view.View.OnClickListener; One ImportAndroid.widget.Button; A  -  Public classMainactivityextendsActivity { -  the     PrivateButton Button =NULL; - @Override -     protected voidonCreate (Bundle savedinstancestate) { -         Super. OnCreate (savedinstancestate); + Setcontentview (r.layout.activity_main); -button =(Button) Findviewbyid (r.id.button_regist); +Button.setonclicklistener (NewOnclicklistener () { A  at              Public voidOnClick (View v) { - Util (); -             } -         }); -     } -     Private voidUtil () { inIntent Intent =NewIntent (mainactivity. This, Registactivity.class); - startactivity (intent); to         //custom Toggle animations for activity + overridependingtransition (r.anim.in, r.anim.out); -     } the}

3.RegistActivity Code

Java code

1  Packagecom.example.regist;2 3 ImportCom.example.android_message. R;4 5 Importandroid.app.Activity;6 ImportAndroid.os.Bundle;7 ImportAndroid.util.Log;8 ImportAndroid.view.View;9 ImportAndroid.view.View.OnClickListener;Ten ImportAndroid.widget.Button; One ImportAndroid.widget.EditText; A ImportAndroid.widget.Toast; - ImportCn.bmob.sms.BmobSMS; - Importcn.bmob.sms.exception.BmobException; the ImportCn.bmob.sms.listener.RequestSMSCodeListener; -  -  Public classRegistactivityextendsActivity { -     PrivateButton Button_send =NULL; +     PrivateEditText EditText =NULL; -  +     protected voidonCreate (Bundle savedinstancestate) { A         Super. OnCreate (savedinstancestate); at Setcontentview (r.layout.regist); -Bmobsms.initialize ( This, "7bb6dee8e0a32ba6eda090f0e7387d77"); -Button_send =(Button) Findviewbyid (r.id.button_send); -EditText =(EditText) Findviewbyid (r.id.edittext); -Button_send.setonclicklistener (NewOnclicklistener () { -  in @Override -              Public voidOnClick (View v) { to Util (); +             } -  the         }); *     } $ Panax Notoginseng     Private voidUtil () { -String number =Edittext.gettext (). toString (); the         if(Number.equals ("") | | Number.length ()! = 11) { +Toast.maketext ( This, "Sorry, send failed! Please enter your phone number correctly", Toast.length_long). Show (); A}Else { the  +Bmobsms.requestsmscode ( This, number, "Test1",NewRequestsmscodelistener () { -  $ @Override $                  Public voidDone (Integer smsId, bmobexception ex) { -                     //TODO auto-generated Method Stub -                     if(ex = =NULL) {//verification code sent successfully theLOG.I ("Bmob", "SMS ID:" + smsId);//used to query this text message send details -                     }Wuyi                 } the             }); -         } Wu     } -}

4.MainActivity Layout File Code

XML code

1 <Relativelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"2 Xmlns:tools= "Http://schemas.android.com/tools"3 Android:layout_width= "Match_parent"4 Android:layout_height= "Match_parent"5 Tools:context= "Com.example.android_message." Mainactivity " >6     <Button7         Android:id= "@+id/button_regist"8 Android:layout_width= "Fill_parent"9 Android:layout_height= "Wrap_content"Ten Android:text= "Register or bind phone number" One         /> A </Relativelayout>

5.RegistActivity Layout File Code

XML code

1 <?XML version= "1.0" encoding= "Utf-8"?>2 <LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"3 Android:layout_width= "Match_parent"4 Android:layout_height= "Match_parent"5 android:orientation= "vertical" >6     <EditText7         Android:id= "@+id/edittext"8 Android:layout_width= "Match_parent"9 Android:layout_height= "Wrap_content"Ten Android:inputtype= "Number" One Android:hint= "Please enter your phone number" A         /> -     <Button -         Android:id= "@+id/button_send" the Android:layout_width= "Match_parent" - Android:layout_height= "Wrap_content" - Android:text= "Send Verification Code" -         /> + </LinearLayout>

Android extension uses Bmob backend cloud to implement SMS verification code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.