注册 登录  
 加关注
查看详情
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

Simon

 
 
 

日志

 
 

Android电话信息相关API  

2011-12-20 13:42:50|  分类: Android |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

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

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<NeighboringCellInfo>

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.

 

 电话拨号

  1. Uri uri=Uri.parse("tel:"+电话号码);  
  2. Intent intent=new Intent(Intent.ACTION_DIAL,uri);  
  3. startActivity(intent);  

其中的电话号码可以通过EditText中输入获得数据,如editText.getText().toString().trim()来获得
上面的代码可以放在Button的onClick方法中调用即可实现拨打电话的功能,调用的是系统的拨号界面。

  评论这张
 
阅读(1549)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018