Android平台提供的电话信息系统管理功能,主要包括:获取电话信息(设备信息、SIM信息以及网络信息)、侦听电话状态(呼叫状态、服务状态、信号强度状态等)和调用电话拨号器。

TelephoneManager类

在Manifest中添加Permission :

TelephonyManager的获得:TelephonyManager tm = (TelephonyManager) this.getSystemService(TELEPHONY_SERVICE);

Constants

String

ACTION_PHONE_STATE_CHANGED

Broadcast intent action indicating that the call state (cellular) on the device has changed.

int

CALL_STATE_IDLE

Device call state: No activity.

空闲(无呼入或已挂机)

int

CALL_STATE_OFFHOOK

Device call state: Off-hook.

摘机(有呼入)

int

CALL_STATE_RINGING

Device call state: Ringing.

响铃(接听中)

int

DATA_ACTIVITY_DORMANT

Data connection is active, but physical link is down

电话数据活动状态类型:睡眠模式(3.1版本)

int

DATA_ACTIVITY_IN

Data connection activity: Currently receiving IP PPP traffic.

电话数据活动状态类型:数据流入

int

DATA_ACTIVITY_INOUT

Data connection activity: Currently both sending and receiving IP PPP traffic.

电话数据活动状态类型:数据交互

int

DATA_ACTIVITY_NONE

Data connection activity: No traffic.

电话数据活动状态类型:无数据流动

int

DATA_ACTIVITY_OUT

Data connection activity: Currently sending IP PPP traffic.

电话数据活动状态类型:数据流出

int

DATA_CONNECTED

Data connection state: Connected.

数据连接状态类型:已连接

int

DATA_CONNECTING

Data connection state: Currently setting up a data connection.

数据连接状态类型:正在连接

int

DATA_DISCONNECTED

Data connection state: Disconnected.

数据连接状态类型:断开

int

DATA_SUSPENDED

Data connection state: Suspended.

数据连接状态类型:已暂停

String

EXTRA_INCOMING_NUMBER

The lookup key used with the ACTION_PHONE_STATE_CHANGED broadcast for a String containing the incoming phone number.

String

EXTRA_STATE

The lookup key used with the ACTION_PHONE_STATE_CHANGED broadcast for a String containing the new call state.

int

NETWORK_TYPE_1xRTT

Current network is 1xRTT

int

NETWORK_TYPE_CDMA

Current network is CDMA: Either IS95A or IS95B

int

NETWORK_TYPE_EDGE

Current network is EDGE

int

NETWORK_TYPE_EHRPD

Current network is eHRPD

int

NETWORK_TYPE_EVDO_0

Current network is EVDO revision 0

int

NETWORK_TYPE_EVDO_A

Current network is EVDO revision A

int

NETWORK_TYPE_EVDO_B

Current network is EVDO revision B

int

NETWORK_TYPE_GPRS

Current network is GPRS

int

NETWORK_TYPE_HSDPA

Current network is HSDPA

int

NETWORK_TYPE_HSPA

Current network is HSPA

int

NETWORK_TYPE_HSPAP

Current network is HSPA+

int

NETWORK_TYPE_HSUPA

Current network is HSUPA

int

NETWORK_TYPE_IDEN

Current network is iDen

int

NETWORK_TYPE_LTE

Current network is LTE

int

NETWORK_TYPE_UMTS

Current network is UMTS

int

NETWORK_TYPE_UNKNOWN

Network type is unknown

int

PHONE_TYPE_CDMA

Phone radio is CDMA.

int

PHONE_TYPE_GSM

Phone radio is GSM.

int

PHONE_TYPE_NONE

No phone radio.

int

PHONE_TYPE_SIP

Phone is via SIP.

int

SIM_STATE_ABSENT

SIM card state: no SIM card is available in the device

int

SIM_STATE_NETWORK_LOCKED

SIM card state: Locked: requries a network PIN to unlock

int

SIM_STATE_PIN_REQUIRED

SIM card state: Locked: requires the user's SIM PIN to unlock

int

SIM_STATE_PUK_REQUIRED

SIM card state: Locked: requires the user's SIM PUK to unlock

int

SIM_STATE_READY

SIM card state: Ready

int

SIM_STATE_UNKNOWN

SIM card state: Unknown.

Fields

public static final String

EXTRA_STATE_IDLE

Value used with EXTRA_STATE corresponding to CALL_STATE_IDLE.

public static final String

EXTRA_STATE_OFFHOOK

Value used with EXTRA_STATE corresponding to CALL_STATE_OFFHOOK.

public static final String

EXTRA_STATE_RINGING

Value used with EXTRA_STATE corresponding to CALL_STATE_RINGING.

Public Methods

int

getCallState()

Returns a constant indicating the call state (cellular) on the device.

CellLocation

getCellLocation()

Returns the current location of the device.

int

getDataActivity()

Returns a constant indicating the type of activity on a data connection (cellular).

处理侦测到的数据活动的改变事件。通过该函数,可以获取数据活动状态信息。

电话数据活动状态类型定义在TelephoneyManager类中。

DATA_ACTIVITY_NONE            无数据流动

DATA_ACTIVITY_IN                    数据流入

DATA_ACTIVITY_OUT                数据流出

DATA_ACTIVITY_INOUT            数据交互

DATA_ACTIVITY_DORMANT     睡眠模式(2.1版本)

int

getDataState()

Returns a constant indicating the current data connection state (cellular).

String

getDeviceId()

Returns the unique device ID, for example, the IMEI for GSM and the MEID or ESN for CDMA phones.

获取设备标识(IMEI)

String

getDeviceSoftwareVersion()

Returns the software version number for the device, for example, the IMEI/SV for GSM phones.获得软件版本

String

getLine1Number()

Returns the phone number string for line 1, for example, the MSISDN for a GSM phone.线路1的电话号码

List

getNeighboringCellInfo()

Returns the neighboring cell information of the device.

String

getNetworkCountryIso()

Returns the ISO country code equivalent of the current registered operator's MCC (Mobile Country Code).获取网络的国家ISO代码

String

getNetworkOperator()

Returns the numeric name (MCC+MNC) of current registered operator.

获取SIM移动国家代码(MCC)和移动网络代码(MNC)

String

getNetworkOperatorName()

Returns the alphabetic name of current registered operator.

获取服务提供商姓名(中国移动、中国联通等)

int

getNetworkType()

Returns a constant indicating the radio technology (network type) currently in use on the device for data transmission.

获取网络类型

NETWORK_TYPE_UNKNOWN 未知网络

NETWORK_TYPE_GPRS

NETWORK_TYPE_EDGE 通用分组无线服务(2.5G)

NETWORK_TYPE_UMTS    全球移动通信系统(3G)

NETWORK_TYPE_HSDPA

NETWORK_TYPE_HSUPA

NETWORK_TYPE_HSPA

NETWORK_TYPE_CDMA         CDMA网络(2.1版本)

NETWORK_TYPE_EVDO_0     CDMA2000 EV-DO版本0(2.1版本)

NETWORK_TYPE_EVDO_A     CDMA2000 EV-DO版本A(2.1版本)

NETWORK_TYPE_EVDO_B     CDMA2000 EV-DO版本B(2.1版本)

NETWORK_TYPE_1xRTT         CDMA2000 1xRTT(2.1版本)

NETWORK_TYPE_IDEN

NETWORK_TYPE_LTE

NETWORK_TYPE_EHRPD

NETWORK_TYPE_HSPAP

int

getPhoneType()

Returns a constant indicating the device phone type.

电话类型

PHONE_TYPE_NONE   未知

PHONE_TYPE_GSM      GSM手机

PHONE_TYPE_CDMA   CDMA手机(2.1版本)

PHONE_TYPE_SIP         via SIP手机

String

getSimCountryIso()

Returns the ISO country code equivalent for the SIM provider's country code.

获取SIM卡中国家ISO代码

String

getSimOperator()

Returns the MCC+MNC (mobile country code + mobile network code) of the provider of the SIM.获得SIM卡中移动国家代码(MCC)和移动网络代码(MNC)

String

getSimOperatorName()

Returns the Service Provider Name (SPN).获取服务提供商姓名(中国移动、中国联通等)

String

getSimSerialNumber()

Returns the serial number of the SIM, if applicable.SIM卡序列号

int

getSimState()

Returns a constant indicating the state of the device SIM card.

SIM卡状态

SIM_STATE_UNKNOWN                   未知状态

SIM_STATE_ABSENT                        未插卡

SIM_STATE_PIN_REQUIRED          需要PIN码,需要SIM卡PIN码解锁

SIM_STATE_PUK_REQUIRED        需要PUK码,需要SIM卡PUK码解锁

SIM_STATE_NETWORK_LOCKED    网络被锁定,需要网络PIN解锁

SIM_STATE_READY                           准备就绪

其中:PIN个人识别码 PUK个人解锁码

String

getSubscriberId()

Returns the unique subscriber ID, for example, the IMSI for a GSM phone.获得客户标识(IMSI)

String

getVoiceMailAlphaTag()

Retrieves the alphabetic identifier associated with the voice mail number.

String

getVoiceMailNumber()

Returns the voice mail number.

boolean

hasIccCard()

boolean

isNetworkRoaming()

Returns true if the device is considered roaming on the current network, for GSM purposes.

void

listen(PhoneStateListener listener, int events)

Registers a listener object to receive notification of changes in specified telephony states.

侦听电话的呼叫状态。

电话管理服务接口支持的侦听类型在PhoneStateListener类中定义。

PhoneStateListener类

Constants

int

LISTEN_CALL_FORWARDING_INDICATOR

Listen for changes to the call-forwarding indicator.

侦听呼叫转移指示器改变事件

int

LISTEN_CALL_STATE

Listen for changes to the device call state.

侦听呼叫状态改变事件

int

LISTEN_CELL_LOCATION

Listen for changes to the device's cell location. Note that this will result in frequent callbacks to the listener.

侦听设备位置改变事件

int

LISTEN_DATA_ACTIVITY

Listen for changes to the direction of data traffic on the data connection (cellular).

侦听数据连接的流向改变事件

int

LISTEN_DATA_CONNECTION_STATE

Listen for changes to the data connection state (cellular).

侦听数据连接状态改变事件

int

LISTEN_MESSAGE_WAITING_INDICATOR

Listen for changes to the message-waiting indicator.

侦听消息等待指示器改变事件

int

LISTEN_NONE

Stop listening for updates.

停止侦听

int

LISTEN_SERVICE_STATE

Listen for changes to the network service state (cellular).

侦听网络服务状态

int

LISTEN_SIGNAL_STRENGTH

This constant is deprecated. by LISTEN_SIGNAL_STRENGTHS

侦听网络信号强度

int

LISTEN_SIGNAL_STRENGTHS

Listen for changes to the network signal strengths (cellular).

Public Constructors

PhoneStateListener()

Public Methods

void

onCallForwardingIndicatorChanged(boolean cfi)

Callback invoked when the call-forwarding indicator changes.

void

onCallStateChanged(int state, String incomingNumber)

Callback invoked when device call state changes.

处理侦测到的电话呼叫状态的改变事件。通过该回调事件,可以获取来电号码,而且可以获取电话呼叫状态。即用switch(state){case TelephoneManager.CALL_STATE_……}来判断

void

onCellLocationChanged(CellLocation location)

Callback invoked when device cell location changes.

void

onDataActivity(int direction)

Callback invoked when data activity state changes.

void

onDataConnectionStateChanged(int state)

Callback invoked when connection state changes.

void

onDataConnectionStateChanged(int state, int networkType)

same as above, but with the network type.

处理侦测到的数据连接状态的改变状态。通过该回调函数,可以获取数据连接状态信息。

数据连接类型

DATA_DISCONNECTED    断开

DATA_CONNECTING         正在连接

DATA_CONNECTED          已连接

DATA_SUSPENDED           已暂停

void

onMessageWaitingIndicatorChanged(boolean mwi)

Callback invoked when the message-waiting indicator changes.

void

onServiceStateChanged(ServiceState serviceState)

Callback invoked when device service state changes.

处理侦测到的服务状态的改变事件。通过该回调函数可以获取服务状态信息。

电话服务状态类型定义在ServiceState类中。

void

onSignalStrengthChanged(int asu)

This method is deprecated. Use onSignalStrengthsChanged(SignalStrength)

处理侦测到的信号强度的改变事件。通过该回调函数,可以获取信号强度类型。

void

onSignalStrengthsChanged(SignalStrength signalStrength)

Callback invoked when network signal strengths changes.

电话拨号

Uri uri=Uri.parse("tel:"+电话号码);

Intent intent=newIntent(Intent.ACTION_DIAL,uri);

startActivity(intent);

其中的电话号码可以通过EditText中输入获得数据,如editText.getText().toString().trim()来获得

上面的代码可以放在Button的onClick方法中调用即可实现拨打电话的功能,调用的是系统的拨号界面。

android电话api,Android电话信息相关API相关推荐

  1. 小程序通过API获取位置信息 微信API 百度地图API

    博客简介 本篇博客介绍如何调用微信API获取经纬度,如何调用百度地图API获取实物位置 微信API获取经纬度信息 百度地图API获取实物位置 微信小程序获取经纬度 微信提供了获取当前设备经纬度的API ...

  2. android metal api,Metal入门002-Metal相关API

    1. MTKView 在MetalKit中提供了一个视图类MTKView,类似于GLKit中GLKView,它是NSView(macOS中的视图类)或者UIView(iOS.tvOS中的视图类)的子类 ...

  3. PHP文件信息相关api

    <?php header('content-type:text/html;charset=utf-8'); date_default_timezone_set('PRC'); $filename ...

  4. php通过api获取天气信息,调用API获取城市天气信息

    Code: /* 调用API获取指定城市的天气数据,并输出 */ echo ""; $url="http://m.weather.com.cn/data/10121010 ...

  5. QLExpress 系列入门教程-07-QLExpress 相关 API 简介

    目录 目录 功能扩展API列表 function 相关 API Operator 相关 API 宏定义相关 API java class 的相关 API 语法树解析变量.函数的 API 语法解析校验 ...

  6. 免费集装箱号识别API免费集装箱信息识别,中国人工智能企业CIMCAI集装箱识别云服务全球4千企业用户,中国人工智能企业智慧港航

    免费集装箱号识别API免费集装箱信息识别API,CIMCAI飞瞳引擎™集装箱人工智能平台全球4千企业用户, 全球领先的飞瞳引擎™AI集装箱识别云服务,集装箱残损识别箱况检测缺陷检验, 小程序拍照检测或 ...

  7. Android未接电话(未接电话个数,以及未接电话信息的读取)

    1.未接电话的产生 /* * 未接来电不能用* Observer监听,不过当有新的未接来电时,系统会发送一个广播com.android * .phone.NotificationMgr.MissedC ...

  8. Android应用生死轮回的那些事儿(3) - 武器库(1)-权限管理相关API

    Android应用生死轮回的那些事儿(3) - 武器库(1)-权限管理相关API PackageManager中提供的武器,可以用"既多又杂,版本变化大"来形容. 不过,我们通过分 ...

  9. hook android api伪造设备信息做刷量

    hook android api伪造设备信息做刷量 概述 Android平台上app的统计数据都是基于Android的设备信息的,比如首次使用(激活),活跃(日活跃DAU,月活跃MAU)等都需要根据设 ...

最新文章

  1. 机器学习与数据挖掘: 基础概念
  2. linq语句复杂查询和分开查询的性能对比
  3. 谈谈java的并发容器、Queue
  4. Wordcount on YARN 一个MapReduce示例
  5. 【OpenCV】OpenCV函数精讲之 -- 命名空间
  6. 启动修复可以尝试将您的计算机还原到,如何修复Windows Bootloader问题(如果您的计算机不启动) | MOS86...
  7. SpringBoot + SpringBatch + Quartz整合定时批量任务
  8. restTemplate设置访问超时
  9. redis安装配置参考
  10. VScode使用记录二:Windows 7下安装GCC、使用VSCode编译代码
  11. 设置Log4j配置文件路径
  12. 网站存在后门 收到公安的网络安全限期整改通知书
  13. UVALive 7461 - Separating Pebbles
  14. 与卿共赴鸿蒙是什么意思,『为君倾笑°‖笑红颜』「古风」唯美的古风句子,古风签必备!...
  15. 2021浙江大学计算机招生目录,【院校】2020-2021浙江大学历史学考研专业目录、院校分析、录取名单...
  16. 10个较好在线商业理念
  17. 通过电脑重置解决小米笔记本巨卡无比的问题
  18. 在win32上用wgl折腾OpenGL 3.3等高版本OpenGL
  19. git 删除历史commit
  20. 解决pycharm里显示数据不完全问题(pandas)

热门文章

  1. ZVM – 记VMP保护代码还原工程
  2. OD命令大全(OllyDbg命令)
  3. 标志寄存器的详细解释
  4. Linux System Programming --Chapter Nine
  5. python中调用函数时必须有实参_Python之函数(一)定义函数以及传参
  6. 认识计算机硬件观评课,观课听课评课评语
  7. c语言编程显示单月日历,任意年月日历输出-题解(C语言代码)
  8. 有不含有重复数字的数组构造二叉树_Leetcode刷题记录:构建最大数二叉树
  9. linux yum 安装vsftp,CentOS下安装安装vsftp
  10. 呼和浩特机器人光缆设备_工业机器人最坚固配件,虐它千万次,性能依旧