目前的安卓开发中,常规的用户名+密码的登录方式已渐渐被账户+短信验证码替换掉。这主要是出于对用户信息安全的保证。现在和大家分享下关于短信验证码的使用。
首先,需要一个电话号码,目前很多账户都是将账户名设置成手机号,然后点击按钮获取手机验证码。
其次,你需要后台给你手机短信的验证接口,各个公司用的不一样,这个身为前端,不需要你来考虑,你只要让你后台给你写好接口,你直接调用就好了。
最后,讲一下操作的请求方式,我这里通过使用xutils进行请求,所以你需要先在你的项目中导入xutils项目包。
这里是具体的操作。
activity_login.xml
布局文件
activity_login.xml
布局文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginTop="20dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:gravity="center"
android:orientation="horizontal">
<EditText
android:id="@+id/mobile_login"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginLeft="10dp"
android:hint="请输入您的手机号"
android:textSize="16sp"
android:background="@null"
android:inputType="number"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="15dp"
android:gravity="center"
android:orientation="horizontal">
<EditText
android:id="@+id/yanzhengma"
android:layout_width="0dp"