Google voice Actions: When the Activity.isVoiceInteraction is true?
Asked Answered
T

0

8

Context:

I'm trying to integrate the google voice actions in my app. I have seen and understood (or at least that what I think) the google codelabs-io2015 example and in this example if you don't modify the code everything works as expected. The problem starts when you attempt to adapt this example to your real use case.

The problem:

So, my problem is that I'm trying to implement the search voice action but Activity#isVoiceInteraction is always false. I don't finally understand when and why the activity is (and when it is not) linked to a voice interactor.

Research:

Looking into the source code of the Activity ,Activity#isVoiceInteraction and Activity#getVoiceInteractor API level 23, I have 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;
}

and the mVoiceInteractor is only initialize on attach function 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());
        }
    }
    ...
}
Tekla answered 30/3, 2016 at 14:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.