Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Incoming call auto answer, play a audio file

In Android, at the time of an incoming call, I want to receive it. Then, from my app, automatically play an audio file during a call and the other party should hear it. Is this possible?

like image 617
Md Maidul Islam Avatar asked Oct 17 '12 07:10

Md Maidul Islam


People also ask

How do I make my android answer automatically?

Samsung phones: Touch Phone and then the three-dot icon in the upper right corner, go to Settings > Answer and end calls > Auto-Answer, and disable the feature. Xiaomi phones: Go to Settings > App settings > System app settings > Phone and disable Auto-Answer.

What does auto answer calls mean?

What Does Auto-Answer Mean? Auto-answer is a feature that enables fax machines and modems to give priority to an incoming call. Voice calls are transferred to voice mail or answering machine, so that fax machines and fax modems can automatically answer and receive faxed documents.


4 Answers

What you are talking about is not exactly possible with android. Android has no access to the in-call audio stream.

Though i can give you a little bit idea about how to do it.

first to intercept incoming call, you need to register a broadcast receiver, which is invoked whenever call is received

public void onReceive(final Context context, Intent intent) 
{
    TelephonyManager telephonyManager = null;
    PhoneStateListener listener = new PhoneStateListener() 
    {
        public void onCallStateChanged(int state, String incomingNumber) 
        {
            switch (state) 
            {
            case TelephonyManager.CALL_STATE_IDLE:
                Toast.makeText(context, "Call Ended..", Toast.LENGTH_LONG).show();
                Log.i("stop", "Call Ended....");
                break;
            case TelephonyManager.CALL_STATE_OFFHOOK:
                Toast.makeText(context, "Call Picked..", Toast.LENGTH_LONG) .show();
                Log.i("received", "Call Picked....");
                break;
            case TelephonyManager.CALL_STATE_RINGING:
                Toast.makeText(context, "Call Ringing.." + incomingNumber,5000).show();
                break;
            }
        }
    };
    // Register the listener with the telephony manager
    telephonyManager.listen(listener, PhoneStateListener.LISTEN_CALL_STATE);

Also change your manifest,

<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE"></uses-permission>
    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <receiver android:name="MyReceiver">

            <intent-filter>

                <action android:name="android.intent.action.NEW_OUTGOING_CALL" />



            </intent-filter>
        </receiver>
    </application>

With this, you can intercept the incoming call and pick the call, now you can try playing some mp3 file in the

case TelephonyManager.CALL_STATE_OFFHOOK:
                // Play mp3 file here
                break;

Hope it helps. Must try this and tell me the experience.

like image 96
Sahil Mahajan Mj Avatar answered Oct 18 '22 03:10

Sahil Mahajan Mj


You cannot play anything to the caller directly. If you want you'd play via loudspeaker, but that's not really what you want. So "no", you cannot do that.

like image 45
Marcin Orlowski Avatar answered Oct 18 '22 03:10

Marcin Orlowski


Try using telephonymanager, it contains the events you are looking for:

  1. http://developer.android.com/reference/android/telephony/TelephonyManager.html#ACTION_PHONE_STATE_CHANGED
like image 3
Tobrun Avatar answered Oct 18 '22 03:10

Tobrun


In android there is no option to play against a live call or switch audio source to something other then default Mic! here are details that why you can't play recordings during a live call

However there are some tricks,

  1. You can play desired recording from mobile speaker, during a call ! an Mic will pick it from there?
  2. Or you can interconnect a handfree Speaker wires to its Mic wire
  3. Or use bluetooh from some other device to play desired recording
like image 1
Nasir Iqbal Avatar answered Oct 18 '22 02:10

Nasir Iqbal