手机号码获取归属地(Android)

本文介绍如何利用阿里提供的开放接口,在Android应用中获取手机号码的归属地,采用MVP架构,核心代码包括HttpUtil.java用于HTTP请求,MvpMainView.java作为接口连接View和逻辑层,MainPresenter.java处理数据并使用Gson解析JSON。
摘要由CSDN通过智能技术生成

我们都知道每个手机号码,都应该有这样的属性:号码、归属地、运营商等。本文将利用阿里提供的开放接口来获取手机号码的归属地。这个工程也简单地运用了mvp的风格来构建工程结构。(点击:工程地址(码云git) 可以下载或查看工程源码)

1.先看看效果图片

这里写图片描述
这里写图片描述

2.再来是工程的目录结构

java

这里写图片描述

res

这里写图片描述

3.工程代码文件

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/darker_gray"
    android:gravity="center_vertical"
    android:orientation="vertical"
    tools:context="com.exmple.phonesearch.MainActivity">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/colorPrimary"
        android:padding="20dp">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:text="手机号码归属地查询"
            android:textColor="#ffffff"
            android:textSize="14sp" />
    </RelativeLayout>

    <EditText
        android:id="@+id/et_phone_input"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:layout_marginTop="20dp"

        android:background="@android:color/background_light"
        android:hint="11位手机号"
        android:inputType="phone"
        android:maxLength="11"
        android:maxLines="1" />

    <Button
        android:id="@+id/btn_search"
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:layout_marginTop="20dp"
        android:background="@color/colorPrimary"
    
  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值