Search code examples
buttonbacktizen

Tizen wearable how to keep app in foreground?


I'm trying to write an app that detects key presses. I have tried all kinds of different types of apps and no success. Tizen watchface does not support HW keys, native service can not detect HW keys because there is no interface. (correct me if i am wrong please - but only if you know it works right now on 2.3.1, because i saw a lot of posts but none seem to be working)

Right now i am working on webApp, that supports background running and HW keys. BUT after some time it always goes to home screen(watch face) How do i prevent that? It is very critical that i can capture Back key after all and any circumstances that is why i don't want it to hide. My back key does not close the app so that is no problem.

THANK YOU! Sincerely Rok

p.s.: and if there is a better way for this problem than an webApp please feel free to suggest what to do to be able to capture back button under all situations. Maybe listening to W_HOME native service that always writes to dlog upon key presses.


Solution

  • You can try the following steps. It worked for me as it prevented from going to watch face when my app is in running state.

    You need to register listener for device wake up. When screen visible, then relaunch your app.

    First: you need add this permission on your config.xml

     <tizen:privilege name="http://tizen.org/privilege/application.launch"/>
     <tizen:privilege name="http://tizen.org/privilege/power"/>

    Second: Yup, you need enable background-support

    try {
      tizen.power.setScreenStateChangeListener(function(prevState, currState) {
       if (currState === 'SCREEN_NORMAL' && prevState === 'SCREEN_OFF') {
           //when screen woke up
           var app = tizen.application.getCurrentApplication();
           tizen.application.launch(app.appInfo.id, function(){
                 //you can do something here when your app have been launch
           });
       }
      });
    } catch (e) {}

    Please go through this link for more details.