Android Question Bluetooth key pressed problem

hookshy

Well-Known Member
Licensed User
Longtime User
I have a problem setting correct Bluetooth headset for handling voice recognition command .
I hit bluetooth key and voice recognition is never stopping !!! after first vr.listen ???

What I succeded is to start activity and voice recognition on activity resume and that is great but somehow do not know how to handle the intent because it seems that this action "android.intent.action.VOICE_COMMAND" is showing on logs no mather the action ..bluetooth headset button pressed ,,vr.listen, ... browser or other intents..

Is something wrong in my code ?
I do have prolems understanding how to parse the intents all though i have passed over some tutorials here ...

B4X:
Sub Activity_Resume ' good practice work with files in activity resume

Log(Activity.GetStartingIntent)

Dim strintent As Intent
strintent=Activity.GetStartingIntent

If strintent.Action = "android.intent.action.VOICE_COMMAND" Then

show_btmode
VR.Prompt="SAY A COMMAND"
VR.listen

End If

End Sub

'here is the manifest declaration

B4X:
AddActivityText(main,  <intent-filter android:priority="1000">
      <action android:name="android.intent.action.VOICE_COMMAND" />
      <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>)
'this is for handling the connection status
AddReceiverText(s2, <intent-filter>
<action android:name="android.bluetooth.device.action.ACL_CONNECTED"/>
<action android:name="android.bluetooth.device.action.ACTION_ACL_DISCONNECTED"/>
</intent-filter>)
AddPermission(android.permission.BLUETOOTH)
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
1. Make strintent a process global variable.
2. Activity_Resume code:
B4X:
Sub Activity_Resume ' good practice work with files in activity resume

Log(Activity.GetStartingIntent)

if Activity.GetStartingIntent <> strintent Then
 strintent=Activity.GetStartingIntent

 If strintent.Action = "android.intent.action.VOICE_COMMAND" Then

 show_btmode
 VR.Prompt="SAY A COMMAND"
 VR.listen

 End If
End If

End Sub
 
Upvote 0

hookshy

Well-Known Member
Licensed User
Longtime User
I have got back the story of the bluetooth button and I find it difficult to make difference between intents ...

I read log and I see this starting intent each time I resume the app either if I press the voice recognition button , browse internet
(Intent) Intent { act=android.intent.action.VOICE_COMMAND flg=0x10000000 cmp=hs.easy.romt/.main }

If I lock the voicerecognition to start only when app start I can not use the headset button a second time ....
If I use vr.listen when starting intent match android.intent.action.Voice_command it loops and starts voicerecognition imediately after vr_result (infinite loop)

Can you suggest me how to solve this problem and make voice recognition start only when the button is pressed ?
Am I doing something wrong ...
 
Last edited:
Upvote 0
Top