TelephonyManager类使用方法大全Word文档下载推荐.docx
《TelephonyManager类使用方法大全Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《TelephonyManager类使用方法大全Word文档下载推荐.docx(32页珍藏版)》请在冰豆网上搜索。
/*
*电话状态:
*1.tm.CALL_STATE_IDLE=0无活动
*2.tm.CALL_STATE_RINGING=1响铃
*3.tm.CALL_STATE_OFFHOOK=2摘机
*/
tm.getCallState();
//int
*电话方位:
*
tm.getCellLocation();
//CellLocation
*唯一的设备ID:
*GSM手机的IMEI和CDMA手机的MEID.
*ReturnnullifdeviceIDisnotavailable.
tm.getDeviceId();
//String
*设备的软件版本号:
*例如:
theIMEI/SV(softwareversion)forGSMphones.
*Returnnullifthesoftwareversionisnotavailable.
tm.getDeviceSoftwareVersion();
*手机号:
*GSM手机的MSISDN.
*Returnnullifitisunavailable.
tm.getLine1Number();
*附近的电话的信息:
*类型:
List<
NeighboringCellInfo>
*需要权限:
android.Manifest.permission#ACCESS_COARSE_UPDATES
tm.getNeighboringCellInfo();
//List<
*获取ISO标准的国家码,即国际长途区号。
*注意:
仅当用户已在网络注册后有效。
*在CDMA网络中结果也许不可靠。
tm.getNetworkCountryIso();
*MCC+MNC(mobilecountrycode+mobilenetworkcode)
仅当用户已在网络注册时有效。
tm.getNetworkOperator();
*按照字母次序的currentregisteredoperator(当前已注册的用户)的名字
tm.getNetworkOperatorName();
*当前使用的网络类型:
NETWORK_TYPE_UNKNOWN网络类型未知0
NETWORK_TYPE_GPRSGPRS网络1
NETWORK_TYPE_EDGEEDGE网络2
NETWORK_TYPE_UMTSUMTS网络3
NETWORK_TYPE_HSDPAHSDPA网络8
NETWORK_TYPE_HSUPAHSUPA网络9
NETWORK_TYPE_HSPAHSPA网络10
NETWORK_TYPE_CDMACDMA网络,IS95A或IS95B.4
NETWORK_TYPE_EVDO_0EVDO网络,revision0.5
NETWORK_TYPE_EVDO_AEVDO网络,revisionA.6
NETWORK_TYPE_1xRTT1xRTT网络7
tm.getNetworkType();
*手机类型:
PHONE_TYPE_NONE无信号
PHONE_TYPE_GSMGSM信号
PHONE_TYPE_CDMACDMA信号
tm.getPhoneType();
*ReturnstheISOcountrycodeequivalentfortheSIMprovider'
scountrycode.
*获取ISO国家码,相当于提供SIM卡的国家码。
tm.getSimCountryIso();
*ReturnstheMCC+MNC(mobilecountrycode+mobilenetworkcode)oftheprovideroftheSIM.5or6decimaldigits.
*获取SIM卡提供的移动国家码和移动网络码.5或6位的十进制数字.
*SIM卡的状态必须是SIM_STATE_READY(使用getSimState()判断).
tm.getSimOperator();
*服务商名称:
中国移动、联通
tm.getSimOperatorName();
*SIM卡的序列号:
READ_PHONE_STATE
tm.getSimSerialNumber();
*SIM的状态信息:
*SIM_STATE_UNKNOWN未知状态0
SIM_STATE_ABSENT没插卡1
SIM_STATE_PIN_REQUIRED锁定状态,需要用户的PIN码解锁2
SIM_STATE_PUK_REQUIRED锁定状态,需要用户的PUK码解锁3
SIM_STATE_NETWORK_LOCKED锁定状态,需要网络的PIN码解锁4
SIM_STATE_READY就绪状态5
tm.getSimState();
*唯一的用户ID:
IMSI(国际移动用户识别码)foraGSMphone.
tm.getSubscriberId();
*取得和语音邮件相关的标签,即为识别符
tm.getVoiceMailAlphaTag();
*获取语音邮件号码:
tm.getVoiceMailNumber();
*ICC卡是否存在
tm.hasIccCard();
//boolean
*是否漫游:
*(在GSM用途下)
tm.isNetworkRoaming();
//
}
code/>
鉴于有些同志没有源码,我把源码粘出来,TelephonyManager.java:
packageandroid.telephony;
importcom.android.internal.telephony.*;
importjava.util.ArrayList;
importjava.util.List;
importandroid.annotation.SdkConstant.SdkConstantType;
importandroid.annotation.SdkConstant;
importandroid.content.Context;
importandroid.os.RemoteException;
importandroid.os.ServiceManager;
importandroid.os.SystemProperties;
*Providesaccesstoinformationaboutthetelephonyserviceson
*thedevice.Applicationscanusethemethodsinthisclassto
*determinetelephonyservicesandstates,aswellastoaccesssome
*typesofsubscriberinformation.Applicationscanalsoregister
*alistenertoreceivenotificationoftelephonystatechanges.
*<
p>
*Youdonotinstantiatethisclassdirectly;
instead,youretrieve
*areferencetoaninstancethrough
*{@linkandroid.content.Context#getSystemService
*Context.getSystemService(Context.TELEPHONY_SERVICE)}.
*Notethatacesstosometelephonyinformationis
*permission-protected.Yourapplicationcannotaccesstheprotected
*informationunlessithastheappropriatepermissionsdeclaredin
*itsmanifestfile.Wherepermissionsapply,theyarenotedinthe
*themethodsthroughwhichyouaccesstheprotectedinformation.
publicclassTelephonyManager{
privatestaticfinalStringTAG="
TelephonyManager"
;
privateContextmContext;
privateITelephonyRegistrymRegistry;
/**@hide*/
publicTelephonyManager(Contextcontext){
mContext=context;
mRegistry=ITelephonyRegistry.Stub.asInterface(ServiceManager.getService(
"
telephony.registry"
));
}
privateTelephonyManager(){
privatestaticTelephonyManagersInstance=newTelephonyManager();
publicstaticTelephonyManagergetDefault(){
returnsInstance;
//
//BroadcastIntentactions
/**
*Broadcastintentactionindicatingthatthecallstate(cellular)
*onthedevicehaschanged.
*
*<
*The{@link#EXTRA_STATE}extraindicatesthenewcallstate.
*IfthenewstateisRINGING,asecondextra
*{@link#EXTRA_INCOMING_NUMBER}providestheincomingphonenumberas
*aString.
pclass="
note"
>
*RequirestheREAD_PHONE_STATEpermission.
*Thiswasa{@linkandroid.content.Context#sendStickyBroadcaststicky}
*broadcastinversion1.0,butitisnolongersticky.
*Instead,use{@link#getCallState}tosynchronouslyquerythecurrentcallstate.
*@see#EXTRA_STATE
*@see#EXTRA_INCOMING_NUMBER
*@see#getCallState
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
publicstaticfinalStringACTION_PHONE_STATE_CHANGED=
android.intent.action.PHONE_STATE"
*Thelookupkeyusedwiththe{@link#ACTION_PHONE_STATE_CHANGED}broadcast
*foraStringcontainingthenewcallstate.
*@see#EXTRA_STATE_IDLE
*@see#EXTRA_STATE_RINGING
*@see#EXTRA_STATE_OFFHOOK
*Retrievewith
*{@linkandroid.content.Intent#getStringExtra(String)}.
publicstaticfinalStringEXTRA_STATE=Phone.STATE_KEY;
*Valueusedwith{@link#EXTRA_STATE}correspondingto
*{@link#CALL_STATE_IDLE}.
publicstaticfinalStringEXTRA_STATE_IDLE=Phone.State.IDLE.toString();
*{@link#CALL_STATE_RINGING}.
publicstaticfinalStringEXTRA_STATE_RINGING=Phone.State.RINGING.toString();
*{@link#CALL_STATE_OFFHOOK}.
publicstaticfinalStringEXTRA_STATE_OFFHOOK=Phone.State.OFFHOOK.toString();
*foraStringcontainingtheincomingphonenumber.
*OnlyvalidwhenthenewcallstateisRINGING.
publicstaticfinalStringEXTRA_INCOMING_NUMBER="
incoming_number"
//DeviceInfo
*Returnsthesoftwareversionnumberforthedevice,forexample,
*theIMEI/SVforGSMphones.
RequiresPermission:
*{@linkandroid.Manifest.permission#READ_PHONE_STATEREAD_PHONE_STATE}
publicStringgetDeviceSoftwareVersion(){
try{
returngetSubscriberInfo().getDeviceSvn();
}catch(RemoteExceptionex){
returnnull;
*ReturnstheuniquedeviceID,forexample,theIMEIforGSM
*phones.
publicStringgetDeviceId(){
returngetSubscriberInfo().getDeviceId();
*Returnsthecurrentlocationofthedevice.
{@linkandroid.Manifest.permission#ACCESS_COARSE_LOCATION
*ACCESS_COARSE_LOCATION}.
publicCellLocationgetCellLocation(){
Bundlebundle=getITelephony().getCellLocation();
returnCellLocation.newFromBundle(bundle);
*Enableslocationupdatenotifications.{@linkPhoneStateListener#onCellLocationChanged
*PhoneStateListener.onCellLocationChanged}willbecalledonlocationupdates.
{@linkandroid.Manifest.permission#CONTROL_LOCATION_UPDATES
*CONTROL_LOCATION_UPDATES}
*@hide
publicvoidenableLocationUpdates(){
getITelephony().enableLocationUpdates();
*Disableslocationupdatenotifications.{@linkPhoneStateListener#onCellLocationChanged
{@linkandroid.Manifest.permission#CONTROL_LOCATION_UPDATES
publicvoiddisableLocationUpdates(){
getITelephony().disableLocationUpdates();
*Returnstheneighboringcellinformationofthedevice.
*@returnListofNeighboringCellInfoornullifinf