Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Wear: Programmatically Wake Screen

Does anyone know how I would go about waking the Wear screen? I'm running the vibration API with:

Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
v.vibrate( getResources().getInteger( R.integer.vibration_duration ) );

which should stop after 2 seconds (2000 milliseconds). This works great if the screen is on, but if the screen is off then the vibration will continue until the screen is touched and woken up.

Edit: I did put together a quick hack to make it work with a timer, but I would like to be able to stop the vibration in a cleaner fashion.

    final Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
    v.vibrate( getResources().getInteger( R.integer.vibration_duration ) );
    Timer timer = new Timer();
    timer.schedule( new TimerTask() {
        @Override
        public void run() {
            v.cancel();
        }
    }, getResources().getInteger( R.integer.vibration_duration ) );

Reedit: That doesn't work every time, soooo yeah, being able to wake the screen would be the best bet. I did get it to work by using a pattern instead of putting in the duration directly, but I'd still love to know how to activate the screen as I feel like this may cause more issues down the line as I keep working with this platform.

    long[] pattern = { 0, getResources().getInteger( R.integer.vibration_duration ) };
    v.vibrate( pattern, -1 );
like image 912
Paul Ruiz Avatar asked Jul 01 '14 19:07

Paul Ruiz


2 Answers

Use NotificationCompat.Builder to create a notification for your app and include a vibrate pattern. This should wake the screen with your notification (and still vibrate for the user). The wearable device is aggressive about returning to a sleep state, particularly if the user doesn't interact with it, so this is probably the simplest approach.

like image 77
Larry Schiefer Avatar answered Sep 28 '22 03:09

Larry Schiefer


I just spent a while trying to figure out how to wake the watch up when I start an activity on the watch remotely via WearableListenerService. What I found that works perfectly on my G Watch R is FLAG_TURN_SCREEN_ON.

getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
like image 29
Benjamin Avatar answered Sep 28 '22 05:09

Benjamin