Skip to content Skip to sidebar Skip to footer

Back Swipe Not Working In Google Glass Activity

I've created a basic activity for Google Glass, but it will not allow me to use the standard down swipe to go back in the stack to the previous activity. I've tried giving the act

Solution 1:

Welcome to doing things on Google Glass -- where not everything works as it should. I've had a slew of issues, but have found some workarounds for some. Either way, setting up the first gesture detection was tricky when I did it to. I'll provide you two working options I have right now running in a glass app I made.

Via onKeyDown():

import android.view.KeyEvent;

    publicbooleanonKeyDown(int keyCode, KeyEvent event) {
        if( keyCode == KeyEvent.KEYCODE_BACK ) {
            // handles swipe downreturntrue;
        }
        elseif (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
            // handles tapreturntrue;
        }
        returnfalse;
    }

Setting up gesture detection is trickier, but it looks like you're missing a lot of code from what you posted. Here's what I have working right now in the app for gesture detection, Ill include just the relevant bits:

import android.view.MotionEvent;

    import com.google.android.glass.touchpad.Gesture;
    import com.google.android.glass.touchpad.GestureDetector;

    privateGestureDetector mGestureDetector;

    @OverrideprotectedvoidonCreate(Bundle savedInstanceState) {
        //instantiate the gesture detector
        mGestureDetector = createGestureDetector(this);
    }

    // Actually create the gesture detectorprivateGestureDetectorcreateGestureDetector(Context context) {
        GestureDetector gestureDetector = newGestureDetector(context);
        gestureDetector.setBaseListener( newGestureDetector.BaseListener() {
            @OverridepublicbooleanonGesture(Gesture gesture) {
                if (gesture == Gesture.SWIPE_RIGHT) { 
                    // pickup right swipereturntrue;
                } elseif (gesture == Gesture.SWIPE_LEFT) {                         
                    // pickup left swipereturntrue;
                } elseif (gesture == Gesture.SWIPE_DOWN) {
                    // pickup down swipereturntrue;
                } elseif (gesture == Gesture.TAP) {
                    // pickup tapreturntrue;
                }
                returnfalse;
            }
        });
        return gestureDetector;
    }

    //Send generic motion events to the gesture detector@OverridepublicbooleanonGenericMotionEvent(MotionEvent event) {
        if (mGestureDetector != null) {
            return mGestureDetector.onMotionEvent(event);
        }
        returnfalse;
    }

As far as you saying this:

    Also, sometimes it works the first time after I install the application, but then it stops working immediately after that.

I have experienced similar problems that I'm still currently trying to resolve. Its hard to troubleshoot that though without knowing more. Have you tried updating the firmware on the Glass? Check that its up to date, otherwise what else are you doing in the code? Maybe you have an issue juggling state information or something if you're switching between activities? Just a guess..

Note: Gesture detection and Key Events for left and right swipes are broken on Glass if you're doing osmething with a MediaPlayer for example. We create a VideoView in a piece of code, and can only detect swipe down and tap and nothing else but we experience this ONLY when in a block of code that is utilizing VideoView/MediaPlayer.

Post a Comment for "Back Swipe Not Working In Google Glass Activity"