I have a Samsung Gear S and I'm bussy writing a web app. I would like to vibrate my app when I get a message from my server. I simply use navigator.vibrate(1000)
and this works just fine. But when my app goes to the background the vibration doesn't work anymore. I've found this thread (https://developer.tizen.org/ko/forums/web-application-development/vibration-background?langswitch=ko) in which they face the same problem but there is no solution. Someone also suggested to use alarms to make your app active but I don't know how to do that. I suppose it is something like this:
var alarm = new tizen.AlarmRelative(1);
var service = navigator.vibrate(1000);
tizen.alarm.add(alarm, "org.tizen.browser", service);
This fails because the service isn't correct. How can I get this to work?
This works for me.
Find the
application.lauch
parameter id in your config.xml.See the example below and the desired privilege and settings.
config.xml:
First Method:
You can turn on the screen light first then vibrate.
It is tricky, but works.
Second Method:
Create a service application which is receive data from server
Create your UI app which need to launch for desired feature.
Make reference in UI app which points to service app
When Service receives data from server, then it will vibrate and lunch the UI app.
In Service app,
The following method:
You can turn on the screen light first then vibrate.
doesn't work quite yet. I had to add a delay for the vibration:
I think background vibration is "not official" supported in web-apps, but you can activate it. Just add following key to your config.xml:
This will allow you to vibrate even if the screen is off. (See also page 12 in tizen-2.3-wrt-core-spec.pdf)
So far this should work, but I think you can't upload an app with this setting to the Tizen-store...
[EDIT]
Today I played a bit with the vibration and just wanted to add my discoveries. If you dont use the 'background-vibration="enable" ' key it seems you have two options, but both are more like a workaround:
Your app need some conditions to be able to vibrate from background:
So for the second way you need to do a bit more stuff. I created a new project with the wizard (TAU basic) and midified the app.js as followed:
So what is done here:
I know this seems to be overloaded to just vibrate, but I think this is the only way to get the vibration 100% to work after the screens was turned off. In https://www.w3.org/TR/2014/WD-vibration-20140211/ they descripe that if the app is not visible it should not vibrate, so I think this is why the screens needs to be on and the app needs to be in foreground. Somehow it seems logical to me that an app can't vibrate if it is in background...
I hope this helps ;)
You can use Alarm.
Add this code fragment when your app receives information from server.