问题
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.
回答1:
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.
回答2:
Why don't you try to use power api? In truth, I didn't test it yet. But I think if you block go to sleep state, it also will not go to home(watchface).
Good luck to you!
https://developer.tizen.org/dev-guide/2.4/org.tizen.web.apireference/html/device_api/mobile/tizen/power.html
1.3. PowerCpuState
Specifies the power state for the CPU resource. enum PowerCpuState { "CPU_AWAKE" }; Since: 2.0
The supported values are:
CPU_AWAKE - The CPU state is set to awake and it does not go to SLEEP state automatically.
来源:https://stackoverflow.com/questions/38287253/tizen-wearable-how-to-keep-app-in-foreground