Open telephony packages:

frameworks/base/telephony/java/android/telephony

TelephonyManagerprovides a way for 3rd applicationinteracting with internal telephony packages.

Class Overview (from androidsdkdocument)

Provides access to information about the telephony services on the device. Applications can use the methods in this class to determine telephony services and states, as well as to access some types of subscriber information. Applications can also register a listener to receive notification of telephony state changes.

You do not instantiate this class directly; instead, you retrieve a reference to an instance throughContext.getSystemService(Context.TELEPHONY_SERVICE).

Note that access to some telephony information ispermission-protected. Your application cannot access the protected information unless it has the appropriate permissions declared in its manifest file. Where permissions apply, they are noted in thethemethods through which you access the protected information.



这个 详细 一下, 这个 演示 第三方 用, P hone S ervic e 及T elephony 关系。

第一条主线,TelephonyManager上半部分PhoneApp一个非常特殊app,通过调用PhoneFactory'创建一个Telephony(Internal),同时第三方application暴露接口,通过TelephonyManager调用,TelephonyManager通过ITelephonyandroid的AIDL机制)获得PhoneInterfaceManager远程对象然后第三方application通过这个远程对象调用service方法这里调用两个独立进程之间进行如果不清楚aidl可以3rdapplication直接调用了PhoneInterfaceManager方法,实际上需要通过TelephonyManager才能调用


第二条主线,TelephonyManager右半部分,TelephonyRegistry,顾名思义,什么东西注册,这种注册一般都是为了实现回调功能这个类主要作用就是第三方Appnew的PhoneStateListener需要监听动作通过调用TelephonyManager注册到TelephonyRegistry,底层状态变化通知GSMPhone时,GSMPhone的DefaultPhoneNotifier通知TelephonyRegistry,然后注册到TelephonyRegistry的PhoneStateListener监听事件会被触发(此时TelephonyRegistry还会发个boardCast),然后回调上层APP复写方法。

(要理清关系的最好办法就是结合图阅读源码,那样会有更深的理解)

如果上面机制看不懂也没关系,作为SDK开发只要知道以下部分行,


If we want to track telephony state in 3rdapplication:

1We should retrive an instance of TelephonyManager and get Phone service. //needed 2 Implement a PhoneStateListener what you want to listen. //not needed 3 You can also register a BroadCastReceiver to receive broadcast if you want. //not needed 4 Don’t forget add permission in manifest file. //needed

Take Settings as example to show how to achieve these.

packages/apps/Settings/src/com/android/settings/deviceinfo/ Status.java

111private TelephonyManager mTelephonyManager;

169private PhoneStateListener mPhoneStateListener = new PhoneStateListener() {

170@Override

171public voidonDataConnectionStateChanged(int state) {

UpdateDataState();//you can override with your own code here

178protected void onCreate(Bundle icicle) {

184mTelephonyManager = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);

268protected void onResume() {

278mTelephonyManager.listen(mPhoneStateListener,

279PhoneStateListener.LISTEN_DATA_CONNECTION_STATE);

337private void updateDataState() {

338int state = mTelephonyManager.getDataState();

341switch (state) {



部分内容参考了http://wenku.baidu.com/view/49699c4f2e3f5727a5e96266.html

更多相关文章

  1. java.lang.NullPointerException Attempt to invoke virtual met
  2. Android(安卓)后台线程调用前台线程的几种方法
  3. android生命周期研究
  4. android使用retrofit
  5. Android集成okhttp
  6. Android(安卓)调用Gmail发送邮件
  7. android
  8. Android布局优化:ViewStub标签实现延迟加载(源码解析原理)
  9. Android(安卓)创建线程执行任务

随机推荐

  1. php artisan命令信息
  2. 预习JS的基本语法,变量,常量 ,函数,对象,
  3. 仿smzdm移动端首页
  4. box-sizing、伪类选择器参数及媒体查询的
  5. JavaScript实现留言板添加删除留言
  6. 原生Js增删改查及解构赋值
  7. TS和JS导出的两种方法
  8. Js基础解析、作用域闭包浅谈及变量与常量
  9. RocketMQ在搜狐的创新实践
  10. 深入浅出理解PHP原理之变量赋值