2011-06-20 11 views
10

मैं एक एंड्रॉइड ऐप पर काम कर रहा हूं जिस पर मैं कॉल करने में सक्षम होना चाहता हूं लेकिन बहुत सटीक प्रतिबंध के साथ, यह "मिस्ड कॉल करना" है। मैं चाहता हूं कि फोन 0 बजने के बाद बस लटकने में सक्षम हो।मिस्ड कॉल कैसे करें?

अभी यह जानने में सक्षम है कि फ़ोन कब कोशिश कर रहा है और कॉल करने के लिए शुरू होता है, लेकिन कुछ सेकंड के लिए नेटवर्क पर कोई "रिंगिंग" गतिविधि नहीं है, जो मैं करना चाहता हूं।

मैं इस सटीक पल को कैसे रोक सकता हूं?

उत्तर

2

PhoneStateListener के माध्यम से onCallStateChanged() का उपयोग आप केवल पता लगा सकते हैं फोन शुरू होता है आउटगोइंग कॉल के बनाने के लिए और जब आउटगोइंग कॉल अप hunged है जब लेकिन आप निर्धारित नहीं कर सकता जब में एक "रिंगिंग" शुरू हो गया है। मैंने एक बार कोशिश की, नीचे दिए गए कोड को देखें:

लापता होने पर आईडीएलई पर डायल किए जाने पर एक आउटगोइंग कॉल आईडीएलई से ऑफफोक से शुरू होती है। आउटगोइंग कॉल शुरू होने के बाद लटकने के लिए टाइमर का उपयोग करना और कुछ ही सेकंड गुजरने का एकमात्र कामकाज है, लेकिन फिर, आपको कभी गारंटी नहीं है कि फोन बजने लगेगा।

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; 
     } 

    } 



} 
संबंधित मुद्दे