我想知道如何在被叫方拨打电话时发出警报。我PhoneStateListener
和BroadcastReceiver
.
一般有三种状态CALL_STATE_IDLE , CALL_STATE_OFFHOOK, CALL_STATE_RINGING
。
CALL_STATE_OFFHOOK
通话接通时状态为通话状态,被叫接听后未调用上述三种状态。
这是我的广播接收器。
public class PhoneStateBroadcastReceiver extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
telephonyManager.listen(new CustomPhoneStateListener(context), PhoneStateListener.LISTEN_CALL_STATE);
}
public class CustomPhoneStateListener extends PhoneStateListener
{
Context context; //Context to make Toast if required
ActivityManager activityManager;
public CustomPhoneStateListener(Context context)
{
super();
this.context = context;
}
@Override
public void onCallStateChanged(int state, String incomingNumber)
{
super.onCallStateChanged(state, incomingNumber);
Log.v("PhoneStateBroadcastReceiver", "onCallStateChanged state"+state);
switch (state)
{
case TelephonyManager.CALL_STATE_IDLE:
Toast.makeText(context, "=CALL_STATE_IDLE==", Toast.LENGTH_LONG).show();
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
Toast.makeText(context, "CALL_STATE_OFFHOOK", Toast.LENGTH_LONG).show();
break;
case TelephonyManager.CALL_STATE_RINGING:
Toast.makeText(context, "CALL_STATE_RINGING", Toast.LENGTH_LONG).show();
break;
default:
break;
}
}
}
}
我已经看到一些应用程序在接听电话时会录制语音。我想知道接听电话的状态。
是否有任何其他状态或侦听器知道被叫方何时接听电话?