给楼主个例子吧。// This file is PhoneCallActivity.java
package com.androidbook.phonecall.demo;import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.view.View;
import android.widget.TextView;public class PhoneCallActivity extends Activity {
    private TextView tv = null;
    private String logText = "";
    private TelephonyManager teleMgr = null;
    private MyPhoneStateListener myListener = null;    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        tv = (TextView)findViewById(R.id.textView);        teleMgr = 
                (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
        myListener = new MyPhoneStateListener();
    }
    
    @Override
    public void onResume() {
     super.onResume();
     Log.d("PhoneCallDemo", "In onResume");
        teleMgr.listen(myListener, PhoneStateListener.LISTEN_CALL_STATE);
    }
    
    @Override
    public void onPause() {
     super.onPause();
     Log.d("PhoneCallDemo", "In onPause");
        teleMgr.listen(myListener, PhoneStateListener.LISTEN_NONE);
    }
    
    public void doClick(View target) {
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("tel:5551212"));
        startActivity(intent);
    }
    
    public class MyPhoneStateListener extends PhoneStateListener
    {
        @Override
        public void onCallStateChanged(int state, String incomingNumber) {
            super.onCallStateChanged(state, incomingNumber);            switch(state)
            {
                case TelephonyManager.CALL_STATE_IDLE:
                    logText = "call state idle...incoming number is["+
                                incomingNumber+"]\n" + logText;
                    break;
                case TelephonyManager.CALL_STATE_RINGING:
                 logText = "call state ringing...incoming number is["+
                                incomingNumber+"]\n" + logText;
                    break;
                case TelephonyManager.CALL_STATE_OFFHOOK:
                 logText = "call state Offhook...incoming number is["+
                                incomingNumber+"]\n" + logText;
                    break;
                default:
                 logText = "call state ["+state+"]incoming number is["+
                                incomingNumber+"]\n" + logText;
                    break;
            }
            tv.setText(logText);
        }
    }
}

解决方案 »

  1.   


    我现在项目中 就是按照这样的方法来实现,但是在一些电信定制android手机上是无法获得incomingNumber。
      

  2.   

    要不就是bsp层和framework层的问题了。
      

  3.   


    这个问题只是在部分电信定制机上出现过。其他类型的android手机还没发现过这种情况
      

  4.   

    网上有种说法读取log日志解析log日志获取,没试过,保留意见。
      

  5.   


    这种方法我也试过,但是有的手机log日志里面有,有的是没有的。
      

  6.   

    蛋疼的android,呼叫高手,大牛
      

  7.   

    既然没传出来,就看framework及更下层的实现了CallTracker(CdmaCallTracker).updatePhoneState()
     -> Phone(CdmaPhone).notifyPhoneStateChnaged()
     -> PhoneNotifier(DefaultPhoneNotifier).notifyPhoneState()
     -> registry(ITelephonyRegistry).notifyCallState()
    (Phone)RPC
    -->TelephonyRegistry.notifyCallState()
    (TelephonyRegistry in system_server)
    callback(IPhoneStateListner).onCallStateChanged()RPC
    -->PhoneStateListner.onCallStateChanged()
    (youApp)
      

  8.   

    在incallScreen中可以获取,只是要晚一两秒钟