Am trying to create a small playground app to learn the VoiceInteractor APIs. I am able to launch the activity from Google Assistant when saying "take a picture" but after the application is launched it does not prompt anything to the user. Below is the code:
AndroidManifest.xml
<activity android:name=".VoiceHandleActivity">
<intent-filter>
<action android:name="android.media.action.STILL_IMAGE_CAMERA" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.VOICE" />
</intent-filter>
</activity>
VoiceHandlActivity.java
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_voice_handle)
if(!isLocalVoiceInteractionSupported) {
finish()
return
}
if(!isVoiceInteraction) {
finish()
return
}
startLocalVoiceInteraction(savedInstanceState)
Log.d("App", "onCreate executed")
}
override fun onLocalVoiceInteractionStarted() {
Log.d("App", "onLocalVoiceInteractionStarted started")
handleVoice()
}
private fun handleVoice() {
val option1: VoiceInteractor.PickOptionRequest.Option = VoiceInteractor.PickOptionRequest.Option("Light", 0)
val option2: VoiceInteractor.PickOptionRequest.Option = VoiceInteractor.PickOptionRequest.Option("Dark", 1)
val options = arrayOf(option1, option2)
val prompt: VoiceInteractor.Prompt = VoiceInteractor.Prompt("Which side are you on")
voiceInteractor.submitRequest(object: VoiceInteractor.PickOptionRequest(prompt, options, null) {
override fun onPickOptionResult(
finished: Boolean,
selections: Array<out Option>?,
result: Bundle?
) {
if (finished && selections?.size == 1) {
if (selections[0].index == 0) findViewById<View>(R.id.vw).setBackgroundColor(Color.GREEN)
else if (selections[0].index == 1) findViewById<View>(R.id.vw).setBackgroundColor(Color.BLUE)
}
}
override fun onCancel() {
finish()
}
})
}
The VoiceHandleActivity gets displayed after launching by Google Assistant but it does not prompt "Which side are you on". Tried calling handleVoice() from onCreate() too but that also does not make the prompt. I am running this on Pixel 2 device with Android 11 installed. Any input on how to get the prompt working.
Update-1
The piece of code is working in Android 10. But when deployed in Android 11, it is not working.
from VoiceInteractor.Prompt with VoiceInteractor.PickOptionRequest does not produce any audio
No comments:
Post a Comment