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)) {
VoiceRecognitionActivity.speak(null);
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)) {
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>
source
share