Namespaces
Variants
Actions

How to vibrate phones from Java ME

Jump to: navigation, search


To vibrate a MIDP2.0 phone in Java ME by using the following method in javax.microedition.lcdui.Display class.

Display.getDisplay(this).vibrate(500);

The duration parameter(in this case 500) is the number of milliseconds the vibrator should be run.

Note, that the duration of the vibration can be limited on certain devices. For example on S60 devices the limit is 10 seconds.


For MIDP 1.0 phones having Nokia UI support you may use the following code which is deprecated in MIDP2.0 phones

com.nokia.mid.ui.DeviceControl.startVibra(50, 1000)

com.nokia.mid.ui.DeviceControl.startVibra(int freq, long duration) The above code activates vibration for a given length of time and frequency

To stop vibration the following code is to be executed

com.nokia.mid.ui.DeviceControl.stopVibra()

Comments

The Display.vibrate() does not work on some (most? all?) Series60 devices. There are several threads in the forum about this. I can confirm that vibrate does not work on my Series60 3rd edition FP1 6290 phone. The same code runs perfectly on a low cost series40v2 6021 phone. This wiki article should give the developers some more information about these problems, which phones have problem, and if there is a workaround.

This page was last modified on 16 December 2011, at 03:57.
108 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2012 All rights reserved