Voice recognition while receiving call
<p>When the phone rings, I want to mute the ringing sound and to start the voice recognition in android. I tried to implement it using the attached code, however it doesn't work for me.</p>

<p>What can I change in order that this code will work?</p>

<pre><code>import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.speech.RecognizerIntent;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.widget.Toast;


public class receivecall extends BroadcastReceiver {
private int REQUEST_CODE = 1234;
Toast toast;
@Override
public void onReceive(Context context, Intent intent) {

    Bundle extras = intent.getExtras();
    if (extras != null) {
        String state = extras.getString(TelephonyManager.EXTRA_STATE);
        if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
            String phoneNumber = extras.getString(TelephonyManager.EXTRA_INCOMING_NUMBER);

                toast = Toast.makeText(context,phoneNumber+"call",Toast.LENGTH_LONG);               
           toast.show();
               Intent i = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
               i.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
                       RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
               i.putExtra(RecognizerIntent.EXTRA_PROMPT, "Voice recognition Demo...");
               context.startActivity(i); 

        }
    }
}
</code></pre>

<hr>

<pre><code>10-05 14:51:50.384: E/AndroidRuntime(559): FATAL EXCEPTION: main
10-05 14:51:50.384: E/AndroidRuntime(559): java.lang.RuntimeException: Unable to instantiate receiver com.example.handsfree.IncomingCallInterceptor: java.lang.ClassNotFoundException: com.example.handsfree.IncomingCallInterceptor
10-05 14:51:50.384: E/AndroidRuntime(559):  at android.app.ActivityThread.handleReceiver(ActivityThread.java:2100)
10-05 14:51:50.384: E/AndroidRuntime(559):  at android.app.ActivityThread.access$1500(ActivityThread.java:123)
10-05 14:51:50.384: E/AndroidRuntime(559):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1197)
10-05 14:51:50.384: E/AndroidRuntime(559):  at android.os.Handler.dispatchMessage(Handler.java:99)
10-05 14:51:50.384: E/AndroidRuntime(559):  at android.os.Looper.loop(Looper.java:137)
10-05 14:51:50.384: E/AndroidRuntime(559):  at android.app.ActivityThread.main(ActivityThread.java:4424)
10-05 14:51:50.384: E/AndroidRuntime(559):  at java.lang.reflect.Method.invokeNative(Native Method)
10-05 14:51:50.384: E/AndroidRuntime(559):  at java.lang.reflect.Method.invoke(Method.java:511)
10-05 14:51:50.384: E/AndroidRuntime(559):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
10-05 14:51:50.384: E/AndroidRuntime(559):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
10-05 14:51:50.384: E/AndroidRuntime(559):  at dalvik.system.NativeStart.main(Native Method)
10-05 14:51:50.384: E/AndroidRuntime(559): Caused by: java.lang.ClassNotFoundException: com.example.handsfree.IncomingCallInterceptor
10-05 14:51:50.384: E/AndroidRuntime(559):  at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
10-05 14:51:50.384: E/AndroidRuntime(559):  at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
10-05 14:51:50.384: E/AndroidRuntime(559):  at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
10-05 14:51:50.384: E/AndroidRuntime(559):  at android.app.ActivityThread.handleReceiver(ActivityThread.java:2095)
10-05 14:51:50.384: E/AndroidRuntime(559):  ... 10 more
10-05 14:51:52.113: I/Exception(538): PhoneStateListener() e = android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.speech.action.RECOGNIZE_SPEECH flg=0x10000000 (has extras) }
10-05 14:52:00.145: I/Process(559): Sending signal. PID: 559 SIG: 9
10-05 14:52:01.553: W/TextToSpeech(538): shutdown failed: not bound to TTS engine
10-05 14:52:03.134: E/ActivityThread(538): Activity com.example.handsfree1.HandsFree has leaked ServiceConnection android.speech.tts.TextToSpeech$Connection@412b7590 that was originally bound here
10-05 14:52:03.134: E/ActivityThread(538): android.app.ServiceConnectionLeaked: Activity com.example.handsfree1.HandsFree has leaked ServiceConnection android.speech.tts.TextToSpeech$Connection@412b7590 that was originally bound here
10-05 14:52:03.134: E/ActivityThread(538):  at android.app.LoadedApk$ServiceDispatcher.&lt;init&gt;(LoadedApk.java:936)
10-05 14:52:03.134: E/ActivityThread(538):  at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:830)
10-05 14:52:03.134: E/ActivityThread(538):  at android.app.ContextImpl.bindService(ContextImpl.java:1117)
10-05 14:52:03.134: E/ActivityThread(538):  at android.content.ContextWrapper.bindService(ContextWrapper.java:370)
10-05 14:52:03.134: E/ActivityThread(538):  at android.speech.tts.TextToSpeech.connectToEngine(TextToSpeech.java:614)
10-05 14:52:03.134: E/ActivityThread(538):  at android.speech.tts.TextToSpeech.initTts(TextToSpeech.java:584)
10-05 14:52:03.134: E/ActivityThread(538):  at android.speech.tts.TextToSpeech.&lt;init&gt;(TextToSpeech.java:547)
10-05 14:52:03.134: E/ActivityThread(538):  at android.speech.tts.TextToSpeech.&lt;init&gt;(TextToSpeech.java:522)
10-05 14:52:03.134: E/ActivityThread(538):  at android.speech.tts.TextToSpeech.&lt;init&gt;(TextToSpeech.java:507)
10-05 14:52:03.134: E/ActivityThread(538):  at com.example.handsfree1.HandsFree.onCreate(HandsFree.java:82)
10-05 14:52:03.134: E/ActivityThread(538):  at android.app.Activity.performCreate(Activity.java:4465)
10-05 14:52:03.134: E/ActivityThread(538):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
10-05 14:52:03.134: E/ActivityThread(538):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
10-05 14:52:03.134: E/ActivityThread(538):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
10-05 14:52:03.134: E/ActivityThread(538):  at android.app.ActivityThread.access$600(ActivityThread.java:123)
10-05 14:52:03.134: E/ActivityThread(538):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
10-05 14:52:03.134: E/ActivityThread(538):  at android.os.Handler.dispatchMessage(Handler.java:99)
10-05 14:52:03.134: E/ActivityThread(538):  at android.os.Looper.loop(Looper.java:137)
10-05 14:52:03.134: E/ActivityThread(538):  at android.app.ActivityThread.main(ActivityThread.java:4424)
10-05 14:52:03.134: E/ActivityThread(538):  at java.lang.reflect.Method.invokeNative(Native Method)
10-05 14:52:03.134: E/ActivityThread(538):  at java.lang.reflect.Method.invoke(Method.java:511)
10-05 14:52:03.134: E/ActivityThread(538):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
10-05 14:52:03.134: E/ActivityThread(538):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
10-05 14:52:03.134: E/ActivityThread(538):  at dalvik.system.NativeStart.main(Native Method)
</code></pre>
