Android中如何监听通话
导读:本文共2131字符,通常情况下阅读需要7分钟。同时您也可以点击右侧朗读,来听本文内容。按键盘←(左) →(右) 方向键可以翻页。
摘要: TelephonyManager作为一个Service接口提供给用户查询电话相关的内容,比如IMEI,LineNumber1等。通过下面的代码即可获得TelephonyManager的实例。TelephonyManagermTelephonyMgr=(TelephonyManager)this.getSystemService(Context.TELEPHONY... ...
目录
(为您整理了一些要点),点击可以直达。publicvoidonCallForwardingIndicatorChanged(booleancfi)
publicvoidonCallStateChanged(intstate,
StringincomingNumber)
publicvoidonCellLocationChanged(CellLocationlocation)
publicvoidonDataActivity(intdirection)
publicvoidonDataConnectionStateChanged(intstate)
publicvoidonMessageWaitingIndicatorChanged(booleanmwi)
publicvoidonServiceStateChanged
(ServiceStateserviceState)
publicvoidonSignalStrengthChanged(intasu)
packagecom.j2medev;
importandroid.app.Activity;
importandroid.content.Context;
importandroid.os.Bundle;
importandroid.telephony.PhoneStateListener;
importandroid.telephony.TelephonyManager;
importandroid.util.Log;
importandroid.widget.TextView;
publicclassTelephonyextendsActivity{
privatestaticfinalStringTAG="Telephony";
TextViewview=null;
@Override
protectedvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
TelephonyManagermTelephonyMgr=(TelephonyManager)this
.getSystemService(Context.TELEPHONY_SERVICE);
mTelephonyMgr.listen(newTeleListener(),
PhoneStateListener.LISTEN_CALL_STATE);
view=newTextView(this);
view.setText("listenthestateofphone\n");
setContentView(view);
}
classTeleListenerextendsPhoneStateListener{
@Override
publicvoidonCallStateChanged(intstate,
StringincomingNumber){
super.onCallStateChanged(state,incomingNumber);
switch(state){
caseTelephonyManager.CALL_STATE_IDLE:{
Log.e(TAG,"CALL_STATE_IDLE");
view.append("CALL_STATE_IDLE"+"\n");
break;
}
caseTelephonyManager.CALL_STATE_OFFHOOK:{
Log.e(TAG,"CALL_STATE_OFFHOOK");
view.append("CALL_STATE_OFFHOOK"+"\n");
break;
}
caseTelephonyManager.CALL_STATE_RINGING:{
Log.e(TAG,"CALL_STATE_RINGING");
view.append("CALL_STATE_RINGING"+"\n");
break;
}
default:
break;
}
}
}
}
<uses-permissionandroid:name=
"android.permission.READ_PHONE_STATE"/>
Android中如何监听通话的详细内容,希望对您有所帮助,信息来源于网络。