PhoneStateListener 中的拨出呼叫检测
我想检测 Android 应用程序中的拨出电话。实际上我可以检测拨出电话,但它也适用于拨入电话,但我不希望这样。我需要它仅用于传出。这是我的代码......
boolean ringing = false;
boolean offhook = false;
public void onCallStateChanged(int state, String incomingNumber) {
switch (state) {
case TelephonyManager.CALL_STATE_IDLE:
if((!ringing)&& offhook){
///incomming call
}
break;
case TelephonyManager.CALL_STATE_RINGING:
callerPhoneNumber = incomingNumber;
Log.d(TAG, "RINGING");
ringing = true;
offhook = false;
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
Log.d(TAG, "OFFHOOK");
offhook = true;
ringing = false;
break;
}
I want to detect outgoing call in android application . Actually I can detect outgoing calls but it is also working for incoming too and I don't want that. I need it to work only for outgoing. here is my code....
boolean ringing = false;
boolean offhook = false;
public void onCallStateChanged(int state, String incomingNumber) {
switch (state) {
case TelephonyManager.CALL_STATE_IDLE:
if((!ringing)&& offhook){
///incomming call
}
break;
case TelephonyManager.CALL_STATE_RINGING:
callerPhoneNumber = incomingNumber;
Log.d(TAG, "RINGING");
ringing = true;
offhook = false;
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
Log.d(TAG, "OFFHOOK");
offhook = true;
ringing = false;
break;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以为
android.intent.action.NEW_OUTGOING_CALL
编写广播接收器。请参阅此处提供示例代码
You can write a broadcast receiver for
android.intent.action.NEW_OUTGOING_CALL
.See here Sample code is available