能够打电话但是有一个非常精确的限制,这是
“打错了电话”.我想要的是,只能挂断电话
一会儿电话开始响了.
现在我可以知道手机何时开始尝试制作
打电话,但几秒钟内没有“响”的活动
网络,这是我愿意做的.
我该如何阻止这个确切的时刻?
解决方法 通过PhonestateListener使用onCallStateChanged(),您只能检测手机什么时候开始拨出电话,并且拨出电话被挂起,但是您无法确定何时启动“振铃”.我试过一下,看看下面的代码:拨打电话时,拨出的电话从空闲状态开始到OFFHOOK,挂断时从空闲状态开始.
唯一的解决方法是在拨出呼叫开始之后使用定时器挂断几秒钟,但是从来没有保证手机将开始响铃.
public abstract class Phonecallreceiver extends broadcastReceiver { static CallStartEndDetector Listener; @OverrIDe public voID onReceive(Context context,Intent intent) { savedContext = context; if(Listener == null){ Listener = new CallStartEndDetector(); } TelephonyManager telephony = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE); telephony.Listen(Listener,PhonestateListener.ListEN_CALL_STATE); } public class CallStartEndDetector extends PhonestateListener { int lastState = TelephonyManager.CALL_STATE_IDLE; boolean isIncoming; public PhonecallStartEndDetector() {} //Incoming call- IDLE to RINGING when it rings,to OFFHOOK when it's answered,to IDLE when hung up //Outgoing call- from IDLE to OFFHOOK when dialed out,to IDLE when hunged up @OverrIDe public voID onCallStateChanged(int state,String incomingNumber) { super.onCallStateChanged(state,incomingNumber); if(lastState == state){ //No change return; } switch (state) { case TelephonyManager.CALL_STATE_RINGING: isIncoming = true; //incoming call started break; case TelephonyManager.CALL_STATE_OFFHOOK: //Transition of ringing->offhook are pickups of incoming calls. nothing down on them if(lastState != TelephonyManager.CALL_STATE_RINGING){ isIncoming = false; //outgoing call started } break; case TelephonyManager.CALL_STATE_IDLE: //End of call(IDle). The type depends on the prevIoUs state(s) if(lastState == TelephonyManager.CALL_STATE_RINGING){ // missed call } else if(isIncoming){ //incoming call ended } else{ //outgoing call ended } break; } lastState = state; } }}总结
以上是内存溢出为你收集整理的android – 如何使错过的电话?全部内容,希望文章能够帮你解决android – 如何使错过的电话?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)