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 阅读(810) 评论(0)  编辑  收藏 所属分类: Android

只有注册用户登录后才能发表评论。


网站导航: