Calvin's Tech Space

          成于堅(jiān)忍,毀于浮躁

             :: 首頁 :: 聯(lián)系 :: 聚合  :: 管理
          1, Listen outgoing call
          Register a broadcast receiver with action android.intent.action.NEW_OUTGOING_CALL,
          but please request to use permission android.permission.PROCESS_OUTGOING_CALLS. we can get outgoing phone number by calling
          String strPhoneNumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
          in BroadcastReceiver.onReceive(xxx);


          2, Listen incoming call
          Use TelephonyManager and PhoneStateListener

          import android.app.Activity;
          import android.content.Context;
          import android.telephony.PhoneStateListener;
          import android.telephony.TelephonyManager;

          public class Telephony extends Activity
          {
              protected void onCreate(Bundle savedInstanceState)
              {
                  super.onCreate(savedInstanceState);
                  TelephonyManager mTelephonyMgr = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
                  mTelephonyMgr.listen(new TeleListener(), PhoneStateListener.LISTEN_CALL_STATE);
           
            setContentView(xxxxxxxx);
           }

          class TeleListener extends PhoneStateListener
          {
              public void onCallStateChanged(int state, String incomingNumber)
              {  
                  super.onCallStateChanged(state, incomingNumber);
                  switch (state)
                  {
                      case TelephonyManager.CALL_STATE_IDLE:
                          //CALL_STATE_IDLE;
                         break;
                      case TelephonyManager.CALL_STATE_OFFHOOK:
                         //CALL_STATE_OFFHOOK;
                         break;
                      case TelephonyManager.CALL_STATE_RINGING:
                         //CALL_STATE_RINGING
                         break;
                      default:
                         break;
                   }
                }

              }
          }
          posted on 2009-12-28 13:16 calvin 閱讀(814) 評論(0)  編輯  收藏 所屬分類: Android
          主站蜘蛛池模板: 广平县| 新津县| 和政县| 启东市| 叶城县| 湖南省| 罗甸县| 周宁县| 兰考县| 萨迦县| 禄丰县| 镇原县| 右玉县| 富裕县| 鄂伦春自治旗| 青岛市| 阜新市| 吉林市| 新沂市| 石泉县| 防城港市| 阜南县| 搜索| 荔波县| 泰兴市| 革吉县| 大余县| 德令哈市| 巴东县| 石嘴山市| 福建省| 凌云县| 韩城市| 同江市| 峨眉山市| 石景山区| 瑞安市| 尚志市| 绩溪县| 梅河口市| 大庆市|