यहां, आउटगोइंग रिसीवर में कक्षा को बुलाए जाने पर इसकी आंतरिक ऑनसेसिव विधि लागू नहीं होती है। लेकिन जब मैं आउटगोइंग रिसीवर क्लास को कॉल कर रहा हूं तो यह केवल इसके कन्स्ट्रक्टर को बुला रहा है। इसके अंदर विधि को कॉल करने में सक्षम नहीं है।

आउटगोइंग कॉल का कनेक्शन स्थापित किया जा सकता है।

कक्षा myListener को कैसे आमंत्रित करें ताकि यह बता सके कि कॉल किस राज्य में है, जैसे ऑनकॉलिंग, ऑनकॉल स्थापित।

इसकी मेनिफेस्ट फ़ाइल है:

 <uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"/> 

     <receiver android:name=".OutgoingReceiver">
        <intent-filter>
            <action android:name="android.intent.action.NEW_OUTGOING_CALL" />
        </intent-filter>
    </receiver>

क्लास आउटगोइंग रिसीवर:-

        import android.content.BroadcastReceiver;
        import android.content.Context;
        import android.content.Intent;
        import android.net.sip.SipAudioCall;
        import android.util.Log;

       public class OutgoingReceiver extends BroadcastReceiver 
       {
        public OutgoingReceiver() 
        {   
           Log.d("outgoing","in outgoing listener");

           //this is been called
        }

     // but not invoking this onRecevie method. Were i am wrong??

      @Override
       public void onReceive(Context context, Intent intent) 
       { 
     Log.d("onRecevice","hi");

     String number = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);

     SipAudioCall.Listener listener = new myListener(context);

   }
 }

MyListener वर्ग: -

    import android.content.Context;
    import android.media.MediaPlayer;
    import android.net.sip.SipAudioCall;
    import android.net.sip.SipException;
    import android.net.sip.SipProfile;
    import android.util.Log;

    class myListener extends SipAudioCall.Listener {
private Context context;

public myListener(Context context)
{
    Log.d("mylistener","i am in");
    this.context = context;
}

@Override
public void onRinging(SipAudioCall call, SipProfile caller) {
    try {
        Log.d("inRinging","in");
        call.answerCall(30);
    } catch (SipException e) {
        e.printStackTrace();
    }
}

@Override
public void onReadyToCall(SipAudioCall call) {
    Log.d("ReadyCall","IncomingCallReceiver.java onReadyToCall : " + call.toString());
}

@Override
public void onCalling(SipAudioCall call) {
    Log.d("Calling","IncomingCallReceiver.java onCalling : " + call.toString());
}

@Override
public void onRingingBack(SipAudioCall call) {
    Log.d("RingingBack","IncomingCallReceiver.java onRingingBack : " + call.toString());
}

@Override
public void onCallEstablished(SipAudioCall call) {
    Log.d("CallEstablished","IncomingCallReceiver.java onCallEstablished : " + call.toString());
    if (call.isInCall()) {
        Log.d("CallEstablished","IncomingCallReceiver.java isInCall : " + call.toString());

    }
    if (call.isOnHold()) { 
        Log.d("CallEstablished","IncomingCallReceiver.java isOnHold : " + call.toString());
    }
    if (call.isMuted()) {
        Log.d("CallEstablished","IncomingCallReceiver.java isMuted : " + call.toString());
    }

    call.startAudio();
}

@Override
public void onCallEnded(SipAudioCall call) {
    Log.d("CallEnded","IncomingCallReceiver.java onCallEnded : " + call.toString());
}

@Override
public void onCallBusy(SipAudioCall call) {
    Log.d("CallBusy","IncomingCallReceiver.java onCallBusy : " + call.toString());
}

@Override
public void onCallHeld(SipAudioCall call) {
    Log.d("CallHeld","IncomingCallReceiver.java onCallHeld : " + call.toString());
}

@Override
public void onError(SipAudioCall call, int errorCode, String errorMessage) {
    Log.d("CallError","IncomingCallReceiver.java IncomingCallReceiver.java onError : " + call.toString() + "; errorCode: " + errorCode + "; errorMessage: " + errorMessage);
}

@Override
public void onChanged(SipAudioCall call) {
    Log.d("CallChanged","IncomingCallReceiver.java onReadyToCall : " + call.toString());
}

}

मुख्य गतिविधि :-

           .
           .   //code
           .

          if(TelephonyManager.CALL_STATE_OFFHOOK == state) 

           {

           Log.i("endcallListener hook", "OFFHOOK");

          IntentFilter intentFilter = new IntentFilter(Intent.ACTION_NEW_OUTGOING_CALL);

         //called here

            BroadcastReceiver br = new OutgoingReceiver();

            getApplicationContext().registerReceiver(br,intentFilter);

        }
       .
       .   //code
       .

आउटपुट:-

       I/endcallListener hook: OFFHOOK
       D/outgoing: in outgoing listener
       //terminated

अग्रिम में धन्यवाद।

0
rkweb03 1 जुलाई 2019, 11:10

1 उत्तर

सबसे बढ़िया उत्तर

यदि आप TelephonyManager का उपयोग करके किसी आउटगोइंग कॉल को कैप्चर करना चाहते हैं तो यह करें:

TelephonyManager tm = (TelephonyManager)context.getSystemService(Service.TELEPHONY_SERVICE);   
tm.listen(listener, PhoneStateListener.LISTEN_CALL_STATE);
PhoneStateListener listener = new PhoneStateListener() {
    @Override
    public void onCallStateChanged(int state, String incomingNumber) {
        // TODO Auto-generated method stub

        super.onCallStateChanged(state, incomingNumber);
        switch(state) {
            case TelephonyManager.CALL_STATE_IDLE:
                break;
            case TelephonyManager.CALL_STATE_OFFHOOK:
                if(incomingNumber==null) {
                    //outgoing call
                } else {
                    //incoming call
                }
                break;
            case TelephonyManager.CALL_STATE_RINGING:
                if(incomingNumber==null) {
                    //outgoing call
                } else {
                    //incoming call
                }
                break;
        }
    }
};
0
Rohit J 1 जुलाई 2019, 11:20