我想知道当被叫者举起电话时如何提醒。我已使用PhoneStateListener
和BroadcastReceiver
。
通常它有三种状态CALL_STATE_IDLE , CALL_STATE_OFFHOOK, CALL_STATE_RINGING
。
CALL_STATE_OFFHOOK
状态正在呼叫,在被呼叫者应答之后,没有呼叫上述三种状态的状态
调用
这是我的BroadcastReceiver。
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;
}
}
}
}
我已经看到一些应用程序在接听电话时录制了一个声音。我想知道接听电话的状态。
是否还有其他州或听众知道被叫方接听电话的时间?
答案 0 :(得分:6)
州将 OFF_HOOK
设备呼叫状态:摘机。至少存在一个拨号,活动或保持的呼叫,并且没有呼叫振铃或等待。
您可以在此链接上看到:
http://developer.android.com/reference/android/telephony/TelephonyManager.html