我想知道如何当被叫方提起呼叫警报。 我已经使用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;
}
}
}
}
我见过一些应用录制语音通话时被接受。 我想知道接受呼叫的状态。
是否有任何其他国家或侦听器时被调用者响应号召,知道吗?