Android电话信息相关API

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

TelephoneManager类

在Manifest中添加Permission :<uses-permission android:name="android.permission.READ_PHONE_STATE" />

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类中。

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wwydpg.html