×

Discussion Board

Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Registered User
    Join Date
    Apr 2011
    Posts
    2

    to set vibrate in j2me

    how to set the lowest vibrate duration in j2me.like display.vibrate(5);

    Regards
    shanthi

  2. #2
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,073

    Re: to set vibrate in j2me

    You need to get the instance of Display and then Vibrate it for required duration.
    display.vibrate(5); should give you vibration for 5 mili second... now you need to try it on the real device and see if it is visible to you or not... or else try to increase it from 5 to 50 to 500 etc and see
    thanks,
    ~Amitabh
    (Champion of the Month -Aug'13)
    Follow me on my blog for Innovative Mobile Apps

  3. #3
    Registered User
    Join Date
    Apr 2011
    Posts
    2

    Re: to set vibrate in j2me

    i tried it,but it not working.

  4. #4
    Registered User
    Join Date
    May 2012
    Posts
    12

    Re: to set vibrate in j2me

    Hi Shanthi Jeyachandhren,

    I have tried making my phone vibrate and was successful. I used nokia e63.
    Were there any errors when you tried?

  5. #5
    Registered User
    Join Date
    May 2012
    Posts
    12

    Re: to set vibrate in j2me

    package ravi.vibrationClass;
    import javax.microedition.lcdui.*;
    import javax.microedition.midlet.*;


    public class Vibrate extends MIDlet implements CommandListener{
    Form form;
    Display disp;
    Command vib,exit;
    public void startApp() {
    form = new Form("Vibration");
    disp = Display.getDisplay(this);
    exit = new Command("Exit", Command.EXIT, 1);
    vib = new Command("Vibrate", Command.OK, 1);
    form.append("Press \"vibrate\" to make the phone vibrate");
    form.addCommand(vib);
    form.addCommand(exit);
    form.setCommandListener(this);
    disp.setCurrent(form);

    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
    notifyDestroyed();
    }

    public void commandAction(Command c, Displayable arg1) {
    if(c == vib){
    disp.vibrate(125);
    }else if(c == exit){
    destroyApp(true);
    }

    }
    }

  6. #6
    Nokia Developer Expert
    Join Date
    Aug 2011
    Posts
    555

    Re: to set vibrate in j2me

    Please use the Nokia.UI API and the startVibra method as specified here on Nokia S60 devices. The method specifies the intensity (frequency) as well as the duration of the vibration. This code should work fine (remember to disconnect the charger or any USB cable connection prior to testing this):
    Code:
    import javax.microedition.lcdui.Command;
    import javax.microedition.lcdui.CommandListener;
    import javax.microedition.lcdui.Display;
    import javax.microedition.lcdui.Displayable;
    import javax.microedition.lcdui.Form;
    import javax.microedition.midlet.MIDlet;
    import javax.microedition.midlet.MIDletStateChangeException;
    
    import com.nokia.mid.ui.DeviceControl;
    
    
    public class VibraMIDlet 
    	extends MIDlet
    	implements CommandListener {
    
    	Form mainForm;
    	Command exitCommand = new Command("Exit", Command.EXIT, 0);
    	Command vibraCommand = new Command("Vibrate", Command.OK, 1);
    	
    	protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
    
    	}
    
    	protected void pauseApp() {
    
    	}
    
    	protected void startApp() throws MIDletStateChangeException {
    		mainForm = new Form("Vibration");
    		mainForm.addCommand(exitCommand);
    		mainForm.addCommand(vibraCommand);
    		mainForm.setCommandListener(this);
    		Display.getDisplay(this).setCurrent(mainForm);
    	}
    
    	public void commandAction(Command c, Displayable arg1) {
    		
    		if(c == vibraCommand) {
    			try{
    				DeviceControl.startVibra(100, 5000);
    			}
    			catch(Exception e) {
    				mainForm.append("Exception:" + e.getMessage());
    			}
    		}
    		
    		if(c == exitCommand) {
    			notifyDestroyed();
    		}
    	}
    
    }
    The lowest vibration duration is theoretically 1 millisecond, but this is hardly noticeable. You might want to try Tactile Feedback if you are developing a game for a Symbian device.
    Please also note, that vibration is not supported on Series 40.
    Last edited by skalogir; 2012-06-08 at 14:27.

  7. #7
    Regular Contributor
    Join Date
    Dec 2012
    Location
    Indonesia,DKI Jakarta
    Posts
    87

    Re: to set vibrate in j2me

    Hello Skalogir,

    i try your code on nokia asha 305. But it's not work. I am very curious cause there is wechat in nokia asha 305. And they can do vibrate. What is wrong with the code..?.

    Code:
    import javax.microedition.lcdui.Command;
    import javax.microedition.lcdui.CommandListener;
    import javax.microedition.lcdui.Display;
    import javax.microedition.lcdui.Displayable;
    import javax.microedition.lcdui.Form;
    import javax.microedition.midlet.MIDlet;
    import javax.microedition.midlet.MIDletStateChangeException;
    
    import com.nokia.mid.ui.DeviceControl;
    
    public class VibraMidlet extends MIDlet implements CommandListener
    {
    	Form mainForm;
    	Command exiCommand = new Command("Exit", Command.EXIT, 0);
    	Command vibraCommand = new Command("Vibrate", Command.OK, 1);
    
    	protected void destroyApp(boolean arg0) throws MIDletStateChangeException
    	{
    		// TODO Auto-generated method stub
    
    	}
    
    	protected void pauseApp()
    	{
    		// TODO Auto-generated method stub
    
    	}
    
    	protected void startApp() throws MIDletStateChangeException
    	{
    		mainForm = new Form("Vibration");
    		mainForm.addCommand(exiCommand);
    		mainForm.addCommand(vibraCommand);
    		mainForm.setCommandListener(this);
    		Display.getDisplay(this).setCurrent(mainForm);
    	}
    
    	public void commandAction(Command c, Displayable arg1)
    	{
    		if (c == vibraCommand)
    		{
    			try
    			{
    				DeviceControl.startVibra(100, 3000);
    			}
    			catch (Exception e)
    			{
    				mainForm.append("Exception: " + e.getMessage());
    			}
    		}
    
    		if (c == exiCommand)
    		{
    			notifyDestroyed();
    		}
    	}
    
    }
    Best Regards,
    iqbal

  8. #8
    Registered User
    Join Date
    Aug 2013
    Posts
    37

    Re: to set vibrate in j2me

    Do this.. Display.getDisplay(this).vibrate(500); this will vibrate for half a second. Also check this.. Goto menu>apps>options>application settings>application vibration>app defined.

  9. #9
    Regular Contributor
    Join Date
    Dec 2012
    Location
    Indonesia,DKI Jakarta
    Posts
    87

    Re: to set vibrate in j2me

    Still not work if i use Display.getDisplay(this).vibrate(500);. Somebody can help...?. For information my device for testing is Nokia Asha 305


    Best Regards,
    Iqbal

    Quote Originally Posted by subha095 View Post
    Do this.. Display.getDisplay(this).vibrate(500); this will vibrate for half a second. Also check this.. Goto menu>apps>options>application settings>application vibration>app defined.

  10. #10
    Registered User
    Join Date
    Aug 2013
    Posts
    37

    Re: to set vibrate in j2me

    Try what i told in the next part of my reply. Like menu>apps> etc etc. Hope that helps.

  11. #11
    Regular Contributor
    Join Date
    Dec 2012
    Location
    Indonesia,DKI Jakarta
    Posts
    87

    Re: to set vibrate in j2me

    Hi subha095,

    I use nokia asha 305. Where is menu app->options...?. In settings..?

  12. #12
    Registered User
    Join Date
    Aug 2013
    Posts
    37

    Re: to set vibrate in j2me

    Try in profiles then. Turn application vibration on. Or you can check file system. Is there any place like game or so. Check there also.

  13. #13
    Regular Contributor
    Join Date
    Dec 2012
    Location
    Indonesia,DKI Jakarta
    Posts
    87

    Re: to set vibrate in j2me

    Quote Originally Posted by subha095 View Post
    Try in profiles then. Turn application vibration on. Or you can check file system. Is there any place like game or so. Check there also.
    Hi subha095,

    Already turn on the vibrate from the system. But still not works. Please, somebody have any other advice or solution.

    Iqbal

  14. #14
    Registered User
    Join Date
    Jan 2009
    Location
    Melbourne, Australia
    Posts
    2,578

    Re: to set vibrate in j2me

    Are you sure it is not just your device being broken?

    Also, please confirm that you tool Skalogir advice: (remember to disconnect the charger or any USB cable connection prior to testing this):

  15. #15
    Regular Contributor
    Join Date
    Dec 2012
    Location
    Indonesia,DKI Jakarta
    Posts
    87

    Re: to set vibrate in j2me

    Quote Originally Posted by hamishwillee View Post
    Are you sure it is not just your device being broken?

    Also, please confirm that you tool Skalogir advice: (remember to disconnect the charger or any USB cable connection prior to testing this):
    Hi Hamishwillee,

    I am sorry. I try it again and it's work. Thank you hamish and skalogir your code really help me.

    Iqball

Similar Threads

  1. How to set background color/image in J2ME
    By CSFYPMAIL in forum Mobile Java Tools & SDKs
    Replies: 6
    Last Post: 2012-01-03, 14:54
  2. vibrate on canvas in j2me
    By Meena ganesan in forum Mobile Java General
    Replies: 5
    Last Post: 2011-04-13, 15:59
  3. to get the last set preferenes in j2me
    By SapnaSrivastav in forum Mobile Java General
    Replies: 3
    Last Post: 2010-10-21, 03:30
  4. Is it possible to set a J2ME app to only work in portrait mode?
    By MobileVisuals in forum Mobile Java General
    Replies: 3
    Last Post: 2010-07-17, 21:03
  5. Alternative to display.vibrate() in J2ME?
    By vics69 in forum Mobile Java General
    Replies: 2
    Last Post: 2006-03-05, 09:07

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •