Calvin's Tech Space

          成于堅忍,毀于浮躁

             :: 首頁 :: 聯系 :: 聚合  :: 管理
          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
          主站蜘蛛池模板: 双柏县| 太仓市| 崇仁县| 徐闻县| 综艺| 遂平县| 页游| 襄垣县| 嘉定区| 西畴县| 彭水| 天气| 微山县| 应城市| 邹城市| 惠安县| 淮北市| 龙井市| 西城区| 平武县| 襄城县| 陈巴尔虎旗| 永安市| 岳普湖县| 庆阳市| 郑州市| 尖扎县| 大田县| 岐山县| 庐江县| 清水县| 博兴县| 宣威市| 东港市| 益阳市| 石渠县| 囊谦县| 申扎县| 乌鲁木齐市| 邹平县| 高淳县|