Recognizerintent.action_recognize_speech Blocked When A Tap Occurs
Solution 1:
If you're still having your problem, try this:
At the very top, declare a private GestureDetector
:
private GestureDetector gestureDetector;
Then, in the onCreate()
method, call a method that creates the GestureDetector
(there is no reason to do it this way over just creating it in the onCreate()
method - it just looks cleaner this way and is more organized):
publicvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
gestureDetector = createGestureDetector(this);
}
The createGestureDetector()
method looks like this:
privateGestureDetectorcreateGestureDetector(Context context) {
GestureDetector gestureDetectorTemp = newGestureDetector(context, newGestureDetector.OnGestureListener() {
//we are creating our gesture detector here@OverridepublicbooleanonDown(MotionEvent motionEvent) {
returnfalse;
}
@OverridepublicvoidonShowPress(MotionEvent motionEvent) {
}
@OverridepublicbooleanonSingleTapUp(MotionEvent motionEvent) { //onTapreturntrue; //<---this is the key
}
@OverridepublicbooleanonScroll(MotionEvent motionEvent, MotionEvent motionEvent2, float distanceX, float distanceY) {
returnfalse; //this is the wrong kind of scroll
}
@OverridepublicvoidonLongPress(MotionEvent motionEvent) {
}
@OverridepublicbooleanonFling(MotionEvent motionEvent, MotionEvent motionEvent2, float v, float v2) {
returnfalse;
}
});
return gestureDetectorTemp;
}
@OverridepublicbooleanonGenericMotionEvent(MotionEvent event) {
if (gestureDetector != null) {
return gestureDetector.onTouchEvent(event);
}
returnfalse;
}
You have to make sure to include the onGenericMotionEvent()
method at the end there. That is what makes sure that your GestureDetector
is notified every time a motion event occurs.
The thing that I added is very minute, but very important - by changing the return value to true
on the onSingleTapUp()
method, you are telling Glass that the event was handled correctly (which in this case, is just doing nothing).
You can read more about GestureDetector
s here.
Post a Comment for "Recognizerintent.action_recognize_speech Blocked When A Tap Occurs"