android 读取短信中的验证码(验证码登录)

本文介绍了如何在Android应用中实现读取短信验证码并自动填充的功能。首先,需要获取读取短信的权限,接着通过布局和特定代码获取短信验证码,最后利用观察者模式监听短信变化,一旦收到验证码短信,即自动填入相应输入框。
摘要由CSDN通过智能技术生成

android 读取短信中的验证码(验证码登录)

1.获取读取短信的权限

 <uses-permission android:name="android.permission.RECEIVE_SMS"/>
  <uses-permission android:name="android.permission.READ_SMS" />

2.获取短信验证码

布局

<?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="@dimen/height_normal"
        android:layout_marginLeft="@dimen/margin_small"
        android:layout_marginRight="@dimen/margin_small"
        android:layout_marginTop="@dimen/margin_small"
        android:background="@drawable/login_input_bg"
        android:gravity="center_vertical"
        android:orientation="horizontal" >

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="@dimen/margin_lsmall"
            android:src="@drawable/user_name_icon" />

        <EditText
            android:id="@+id/et_username"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@null"
            android:hint="手机号/邮箱/用户名"
            android:paddingLeft="@dimen/padding_lsmall"
            android:textColor="@color/
  • 3
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值