语言

Menu
Sites
Language
Gear S3 Watch resume application on leaving low power mode

I have written a stopwatch-type timer application to keep track of multiple timings when cooking.

After a few seconds of no input, the watch goes to the default always-on watchface, which is what I want it to do.

If I re-activate the watch quickly, the display re-activates with my application still running, which again is what I want it to do.

If the watch is inactive for about a minute, then re-activating it brings up the normal watch face.  When I re-start the application, it has remembered its internal state.  I am using real-time timestamps for the timer start events, so all of my timers are still running and correct.

What I want is that when I re-activate the watch after low-power mode, it resumes my application instead of the normal watch face, no matter how long I have left the watch in low-power mode.  I have not been able to find the API for this on the web.  Could someone help me please?

 

响应

2 回复
Armaan-Ul- Islam

You cannot change the 'Low Power' Mode/'Power Saving Mode' behavior, But what I can suggest you is to launch Home app (Which is 'watchface' in case of wearable) while the screen is off for a specific duration.

 

You need to use tizen 'Power API' and 'Application API' for that. Set a screen state change listener and launch home/watchface while the screen is off. I'm sharing a draft sample code for you, Change this according to your need.

 

function onLaunchSuccess () {
    console.log("Launched Home");}

function onLaunchError () {
    console.log("Cannot Launch Home");}

function launchWatchFace(){
	var appId ="com.samsung.w-home";        // For Samsung gear device
	var appId2 = "org.tizen.w-home";	// For Emulator
	tizen.application.launch(appId, onLaunchSuccess, onLaunchError); 
}

function onScreenStateChanged(previousState, changedState) {
    if(changedState=='SCREEN_OFF'){
    	console.log("Screen off Event");
    	launchWatchFace();
    }
}
tizen.power.setScreenStateChangeListener(onScreenStateChanged);

 

Add 'power' and 'application.launch' privileges in config.xml file. And you have to add a background-category in config.xml-> Tizen -> Background-category > + Otherwise your app won't operate while it's on background or screen is off.

 

Relevant documentations:

https://developer.tizen.org/development/guides/web-application/device-settings-and-systems/power-states

https://developer.tizen.org/community/code-snippet/web-code-snippet/launch-%E2%80%98settings%E2%80%99-app-wearable-web-application-0

 

John Phoenix

Hi Armaan,

Thanks for taking the time to reply.  I have been a bit busy and haven't had time to look at my app again until now.

While I have been programming for many years, this is my first mobile app and I am still trying to understand how the OS environment works.  From your reply, I think you are suggesting that I need another app to manage and re-launch my stopwatch app.  That sounds a bit complicated.

I found this thread on the Samsung developers forum:

https://developer.samsung.com/forum/thread/how-to-bring-application-to-focus-when-display-turns-on/201/295027?boardName=SDK&startId=zzzzz~&curPage=2

This descibes a way to add the ScreenStateChangeListener in my own application.

I had some trouble enabling background mode in Tizen Studio.  I had to change the Tizen version of my App from 3.0 to 2.3 to make this option available in the GUI.  With this setting, the code snippet in the thread that I have linked to is doing what I wanted.