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:
public boolean isVoiceInteraction() {
return mVoiceInteractor != null;
}
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());
}
}
...
}