Auto answer the incoming call programmatically?
Asked Answered
A

1

10

I have the code for getting the number of the incoming call to a android phone. But I want to automatically answer the call when the incoming call is from a particular number.

I found this code on the internet:

public class ServiceReceiver extends BroadcastReceiver {
    private static final String TAG = null;

    @SuppressWarnings({"unchecked", "rawtypes"})
    @Override
    public void onReceive(Context context, Intent intent) {
        Toast.makeText(context, "GOT SOMETHING", Toast.LENGTH_SHORT).show();
        MyPhoneStateListener phoneListener = new MyPhoneStateListener();
        TelephonyManager telephony = (TelephonyManager)
                context.getSystemService(Context.TELEPHONY_SERVICE);
        telephony.listen(phoneListener, PhoneStateListener.LISTEN_CALL_STATE);
        Bundle bundle = intent.getExtras();
        String phoneNr = bundle.getString("incoming_number");
        Log.v(TAG, "phoneNr: " + phoneNr);
        String numb = "+4348873541";

        Class c = Class.forName(telephony.getClass().getName());
        Method m = c.getDeclaredMethod("getITelephony");
        m.setAccessible(true);
        if (phoneNr.equals(numb)) {
            ITelephony telephonyService = (ITelephony) m.invoke(telephony);
            telephonyService = (ITelephony) m.invoke(telephony);
            telephonyService.silenceRinger();
            telephonyService.answerRingingCall();
        }
    }
}

Can you please tell me how to auto answer the call from a particular number?

Australopithecus answered 5/1, 2012 at 9:33 Comment(2)
I tried this code, but does not seem to work. Im using Samsung Galaxy, android version 2.2. Do you think it is because of the version???Australopithecus
Unfortunately bluetooth solution works not in all cases - https://mcmap.net/q/618882/-how-to-programmatically-answer-a-callFoliated
I
8

As from here

Check this source

They send a Bluetooth "keydown" event to answer the call!

Innovation answered 12/1, 2012 at 13:36 Comment(1)
+1 for not blindly copying the link, but explaining the idea on how they do it.Plotter

© 2022 - 2024 — McMap. All rights reserved.