Google Voice Actions: when is the Activity.isVoiceInteraction action true?

Context

I am trying to integrate Google voice actions in my application. I saw and understood (or at least what I think) the google codelabs-io2015 example , and in this example, if you do not change the code, it works as expected. The problem starts when you try to adapt this example to a real use case.

Problem :

So my problem is that I'm trying to implement a voice search action , but the # isVoiceInteraction Action is always false . I do not understand when and why activity (and when not) is associated with voice interaction.

Study

Looking at the source code for Activity , Action # isVoiceInteraction and Action # getVoiceInteractor API Level 23 , I found the following:

 /**
 * Check whether this activity is running as part of a voice interaction with the user.
 * If true, it should perform its interaction with the user through the
 * {@link VoiceInteractor} returned by {@link #getVoiceInteractor}.
 */
public boolean isVoiceInteraction() {
    return mVoiceInteractor != null;
}

/**
 * Retrieve the active {@link VoiceInteractor} that the user is going through to
 * interact with this activity.
 */
public VoiceInteractor getVoiceInteractor() {
    return mVoiceInteractor;
}

It is mVoiceInteractorinitialized only by a function attach, as shown below:

final void attach(Context context, ActivityThread aThread,
        Instrumentation instr, IBinder token, int ident,
        Application application, Intent intent, ActivityInfo info,
        CharSequence title, Activity parent, String id,
        NonConfigurationInstances lastNonConfigurationInstances,
        Configuration config, String referrer, IVoiceInteractor voiceInteractor) {
    ...
    mLastNonConfigurationInstances = lastNonConfigurationInstances;
    if (voiceInteractor != null) {
        if (lastNonConfigurationInstances != null) {
            mVoiceInteractor = lastNonConfigurationInstances.voiceInteractor;
        } else {
            mVoiceInteractor = new VoiceInteractor(voiceInteractor, this, this,
                    Looper.myLooper());
        }
    }
    ...
}
+4
source share

All Articles