Android Call Recognition Call Adapter

I would be very grateful if someone knows how to solve this.

My problem: I need voice recognition to start with the fact that the call was detected through the Android application so that a person can accept, reject call numbers or dial numbers only by voice.

1. Currently, the task is activated after the call is completed. ie Voice recognition starts after a call, but I need it to appear during an incoming call to confirm a command, such as “Answer Phone”, to receive the call.

public void onReceive(Context context, Intent intent) {

        if (intent.getStringExtra(TelephonyManager.EXTRA_STATE).equals(
                TelephonyManager.EXTRA_STATE_RINGING)) {
            // This code will execute when the phone has an incoming call
            VoiceRecognitionActivity.speak(null);

            // get the phone number
            String incomingNumber = intent
                    .getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
            Toast.makeText(context, "Call from:" + incomingNumber,
                    Toast.LENGTH_LONG).show();

        } else if (intent.getStringExtra(TelephonyManager.EXTRA_STATE).equals(
                TelephonyManager.EXTRA_STATE_IDLE)
                || intent.getStringExtra(TelephonyManager.EXTRA_STATE).equals(
                        TelephonyManager.EXTRA_STATE_OFFHOOK)) {
            // This code will execute when the call is disconnected
            Toast.makeText(context, "Detected call hangup event",
                    Toast.LENGTH_LONG).show();

        }
    }
}

 <activity
            android:name="com.white.rabbit.MyCallReceiver"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
+4
source share

Source: https://habr.com/ru/post/1547708/


All Articles