Android Wear: software wake up screen

Does anyone know how I will wake up the Wear screen? I am 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, the vibration will continue until the screen touches and wakes up.

Edit: I put together a quick hack so that it works with a timer, but I would like it to be able to stop the vibration in a cleaner way.

  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: It doesn't work every time, soooo yes, being able to wake up the screen would be a better choice. I got it to work using the template instead of directly entering the time, but I still would like to know how to activate the screen, since I feel that this can cause more problems as I continue to work with this platform.

  long[] pattern = { 0, getResources().getInteger( R.integer.vibration_duration ) }; v.vibrate( pattern, -1 ); 
+6
source share
2 answers

Use NotificationCompat.Builder to create a notification for your application and enable a vibrating template. This should wake up the notification screen (and still vibrate for the user). The wearable device aggressively refers to the return to sleep, especially if the user does not interact with it, so this is probably the easiest approach.

+3
source

I just spent some time trying to figure out how to wake up an hour-long game when I start a watch activity remotely through the WearableListenerService. What I found works fine on my G Watch R, FLAG_TURN_SCREEN_ON .

 getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON); 
+1
source

Source: https://habr.com/ru/post/971618/


All Articles