WEB开发网
开发学院手机开发Android 开发 Android 实现通话监听 阅读

Android 实现通话监听

 2010-05-19 16:16:00 来源:WEB开发网   
核心提示:import android.telephony.PhoneStateListener;import android.telephony.TelephonyManager;import android.util.Log;import android.widget.TextView;public class Teleph

import android.telephony.PhoneStateListener;

import android.telephony.TelephonyManager;

import android.util.Log;

import android.widget.TextView;

public class Telephony extends Activity {

private static final String TAG = "Telephony";

TextView view = null;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

TelephonyManager mTelephonyMgr = (TelephonyManager) this

.getSystemService(Context.TELEPHONY_SERVICE);

mTelephonyMgr.listen(new TeleListener(),

PhoneStateListener.LISTEN_CALL_STATE);

view = new TextView(this);

view.setText("listen the state of phone ");

setContentView(view);

}

class TeleListener extends PhoneStateListener {

@Override

public void onCallStateChanged(int state,

String incomingNumber) {

super.onCallStateChanged(state, incomingNumber);

switch (state) {

case TelephonyManager.CALL_STATE_IDLE: {

Log.e(TAG, "CALL_STATE_IDLE");

view.append("CALL_STATE_IDLE " + " ");

break;

}

case TelephonyManager.CALL_STATE_OFFHOOK: {

Log.e(TAG, "CALL_STATE_OFFHOOK");

view.append("CALL_STATE_OFFHOOK" + " ");

break;

}

case TelephonyManager.CALL_STATE_RINGING: {

Log.e(TAG, "CALL_STATE_RINGING");

view.append("CALL_STATE_RINGING" + " ");

break;

}

default:

break;

}

}

}

}

不要忘记在AndroidManifest.xml里面添加个permission.

< uses-permission android:name=

"android.permission.READ_PHONE_STATE" />

以上即Android监听通话的具体操作方法

上一页  1 2 

Tags:Android 实现 通话

编辑录入:coldstar [复制链接] [打 印]
赞助商链接