- This topic has 3 replies, 3 voices, and was last updated 11 years, 9 months ago by Unknown Author.
-
AuthorPosts
-
support-michaelKeymasteredited: Jan 9, 2013, fixed issue with attached project. Note the project requires MobiOne 2.3 or greater.
Vibrate ExampleThe following example project demonstrates how to vibrate the device at a user defined interval using the Cordova/PhoneGap vibrate api. You must create an app from the project for the device api to function; this project will not run in the Test Center as it does not emulate the Cordova api.
The app UI consists of a SelectListMenu(spinner) for setting the frequency that the device should vibrate and a Start and Stop button. The Start and Stop buttons have attached OnClick(RunJS) actions that respectively run custom start() and stop() javascript functions that I have created (see code below). The start() function starts a javascript timer (setInterval() js function) that runs at the frequency in seconds specified in the SelectListMenu. The stop() function clears the timer using the clearInterval() function.The Start button also serves as a restart action if the timer is already running.
The mobione design file for this app is attached at the bottom.
See attachment vibrate-ss.png
The app javascript is available in the vibrate_custom.js file.
//----------------------------------- timerId = -1; frequency = 1; //seconds isRunning = false; showNoCordovaMsg = true; VIBRATE_DURATION = 250; //milliseconds COLOR_GREEN = '#007000'; COLOR_RED = '#E10000'; function start() { if (showNoCordovaMsg && !phoneui.cordovaAvailable ()) { alert('Vibrate feature is only available for \nHTML5 apps. '); showNoCordovaMsg = false; } if (isRunning) { //restart stop(); start(); return; } isRunning = true; showStatus('Running...',COLOR_GREEN); frequency = $('select[name="frequency"]').val() timerId = setInterval( function() { if (phoneui.cordovaAvailable ()){ navigator.notification.vibrate(VIBRATE_DURATION); } }, frequency * 1000 + VIBRATE_DURATION); } function stop() { if (!isRunning) return; isRunning = false; clearInterval(timerId); showStatus('Stopped',COLOR_RED); } ....
See the following guides if you need assistance creating either an iOS application or an Android application from this project.
Source Code See attachment vibrate.zip
Attachments:
You must be logged in to view attached files.
johnnyboyMemberI cant get this example to vibrate…
I have tested it on both Iphone4 and Ipad
Berfore updating to 2.3.0 (=today) I could not even see the GUI.
After the upodate I was able to see and run the application.
Is there somthing I need to do to get the PhoneGap functionality to work.
(I have also tested the BarCodeReader Demo.. I can see and run the App in 2.3.0 but it seams not to be working ;-(
help me to get the examples and PhoneGap functions to work
Regards
support-michaelKeymasterPlease see the edited article above. I completely goofed originally and did not upload the entire project. I have fixed the problem. Download the zip, build an ios or android app and give it a go.
Unknown AuthorParticipantHow about vibrating twice (or more) in a row, one right after the other? I’m interested for an iOS app and don’t know if that violates some iOS rule.
-1TC
-
AuthorPosts