Abdul Rahman Abdul Rahman - 1 month ago 7
Android Question

How pragmatically receive the recipient call without user interaction in Android

I want to write an Android code which automatically receive recipient phone call without user interaction?
Is there anyway/possibility to do this or I am just wasting of my precious time?
As I have google but not found any related result?

Answer Source

I tried to implement same thing and Its work perfectly but for some devices it doesn't work..

private void acceptCall() {

        new Thread(new Runnable() {

            @Override
            public void run() {
                try {
                    System.out.println("execute input keycode headset hook");
                    System.out.println("input keyevent " + Integer.toString(KeyEvent.KEYCODE_HEADSETHOOK));
                    Runtime.getRuntime().exec("input keyevent " + Integer.toString(KeyEvent.KEYCODE_HEADSETHOOK));

                } catch (IOException e) {
                    // Runtime.exec(String) had an I/O problem, try to fall back
                    System.out.println("send keycode headset hook intents");
                    String enforcedPerm = "android.permission.CALL_PRIVILEGED";
                    Intent btnDown = new Intent(Intent.ACTION_MEDIA_BUTTON).putExtra(
                            Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_HEADSETHOOK));

                    Intent btnUp = new Intent(Intent.ACTION_MEDIA_BUTTON).putExtra(
                            Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_HEADSETHOOK));

                    sendOrderedBroadcast(btnDown, enforcedPerm);
                    sendOrderedBroadcast(btnUp, enforcedPerm);

                    System.out.println("Exception " + e.toString());
                }
            }

        }).start();

    }