regarding Vibration code

Forum for J2ME mobile games related topics including programming doubts, books and other resources for J2ME game development

regarding Vibration code

Postby uvrpavan » Thu Jun 21, 2007 9:19 am

hi
i want to know the code to vibrate the mobile
tell me the apis u r using
and send me the function to vibrate the mobile



For the Nokia mobile
uvrpavan
 
Posts: 19
Joined: Sun Feb 11, 2007 8:52 am

Postby DevelopmentTeam » Thu Jun 21, 2007 11:15 am

This example will explain you all about Vibration and lights on/off

Code: Select all
import javax.microedition.midlet.*;
import com.nokia.mid.ui.DeviceControl;
import javax.microedition.lcdui.*;

public class NokiaUITest extends MIDlet implements CommandListener{

private Command _cmdExit = null;
private Command _cmdVibrate = null;
private Command _cmdBacklightOn = null;
private Command _cmdBacklightOff = null;
private Command _cmdBacklightFlash = null;


private Form _mainForm = null;
private Display _display = null;

public NokiaUITest() {

_cmdExit = new Command("Schliessen", Command.EXIT, 1);
_cmdVibrate = new Command("Vibrieren", Command.SCREEN, 1);
_cmdBacklightOn = new Command("Backlight ON", Command.SCREEN, 2);
_cmdBacklightOff = new Command("Backlight OFF", Command.SCREEN, 2);
_cmdBacklightFlash = new Command("Flash Backlight", Command.SCREEN, 3);

_mainForm = new Form("Status NokiaUI Test:");
_display = Display.getDisplay(this);

_mainForm.addCommand(_cmdExit);
_mainForm.addCommand(_cmdVibrate);
_mainForm.addCommand(_cmdBacklightOn);
_mainForm.addCommand(_cmdBacklightOff);
_mainForm.addCommand(_cmdBacklightFlash);

_mainForm.setCommandListener(this);
}

protected void startApp() throws MIDletStateChangeException {
_display.setCurrent(_mainForm);
}

protected void pauseApp() { }

protected void destroyApp(boolean uc) { }

public void commandAction(Command cmd, Displayable disp) {

if(cmd == _cmdExit){
_mainForm.append("EXIT MIDlet... \n");
this.destroyApp(false);

}else if(cmd == _cmdVibrate){
_mainForm.append("Vibra for 2 Seconds (Freq:100)... \n");
DeviceControl.startVibra(100, 2000);

}else if(cmd == _cmdBacklightOn){
_mainForm.append("Turn Backlight ON \n");
DeviceControl.setLights(0, 100);

}else if(cmd == _cmdBacklightOff){
_mainForm.append("Turn Backlight OFF \n");
DeviceControl.setLights(0, 0);

}else if(cmd == _cmdBacklightFlash){
_mainForm.append("Flashing Light for 2s \n");
DeviceControl.flashLights(2000);
}


}
}
User avatar
DevelopmentTeam
Site Admin
 
Posts: 661
Joined: Tue Aug 15, 2006 8:39 am
Location: India

Postby DevelopmentTeam » Thu Jun 21, 2007 11:17 am

Also
The MIDP 2.0 provide us the vibration and Backlight support. u can get those methods on Display class , Display.vibrate() , Display.flashBackLight() and I think these fucntion should work on all MIDP 2.0 dvices , if device have Vibration and BackLight support
User avatar
DevelopmentTeam
Site Admin
 
Posts: 661
Joined: Tue Aug 15, 2006 8:39 am
Location: India

Postby DevelopmentTeam » Thu Jun 21, 2007 11:19 am

All these functions may or may not work in Nokia S60 devices. As they have known issues on such things. There is no fix for this problem. In 6600 it is really hard to make it work all the time.
User avatar
DevelopmentTeam
Site Admin
 
Posts: 661
Joined: Tue Aug 15, 2006 8:39 am
Location: India


Return to J2ME Games

Who is online

Users browsing this forum: Majestic-12 [Bot] and 1 guest

cron