2

Добрый день! Целый день безрезультатно пытаюсь найти ответ на вопрос как можно завершить звонок на телефоне? Сделать вызов можно с помощью Intent в BroadcastReceiver можно получить состояние телефона, а как можно сбросить вызов? В общем как программно положить трубку? Спасибо!

2 ответа 2

2
    Bundle myBundle = intent.getExtras();
    if (myBundle != null) {
        System.out.println("--------Not null-----");
        try {
            if (intent.getAction().equals("android.intent.action.PHONE_STATE")) {
                String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
                System.out.println("--------in state-----");
                if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
                    // Incoming call
                    String incomingNumber = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
                    System.out.println("--------------my number---------" + incomingNumber);

// this is main section of the code,. could also be use for particular number.
                    // Get the boring old TelephonyManager.
                    TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);

                    // Get the getITelephony() method
                    Class<?> classTelephony = Class.forName(telephonyManager.getClass().getName());
                    Method methodGetITelephony = classTelephony.getDeclaredMethod("getITelephony");

                    // Ignore that the method is supposed to be private
                    methodGetITelephony.setAccessible(true);

                    // Invoke getITelephony() to get the ITelephony interface
                    Object telephonyInterface = methodGetITelephony.invoke(telephonyManager);

                    // Get the endCall method from ITelephony
                    Class<?> telephonyInterfaceClass = Class.forName(telephonyInterface.getClass().getName());
                    Method methodEndCall = telephonyInterfaceClass.getDeclaredMethod("endCall");

                    // Invoke endCall()
                    methodEndCall.invoke(telephonyInterface);
                }

            }
        } catch (Exception ex) { // Many things can go wrong with reflection calls
            ex.printStackTrace();
        }
    }
1

К ответу gadfil, необходимо добавить, что это все делается в BroadcastReceiver.

И не забыть добавить в манифест

android.permission.CALL_PHONE

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.