×

Discussion Board

Results 1 to 3 of 3

Thread: accelerometer

  1. #1
    Registered User
    Join Date
    Dec 2010
    Posts
    39

    accelerometer

    Hi to all
    i am developing a game for touch and non touch mobiles using J2ME. Here i am using accelerometer, how can i identify the accelerometer supported device. Is there is any system properties to find it?

    thanks
    Mohamed Nazar

  2. #2
    Regular Contributor
    Join Date
    Dec 2011
    Posts
    174

    Re: accelerometer

    Hi nazar.ooty,

    You can check the Mobile Sensor API support with the system property microedition.sensor.version
    http://library.developer.nokia.com/i...75E4F95CB.html

    -tiviinik

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

    Re: accelerometer

    or you could query the device's sensors to see if accelerometer exists by using this code:

    Code:
    import javax.microedition.io.Connector;
    import javax.microedition.lcdui.*;
    import javax.microedition.midlet.MIDlet;
    import javax.microedition.sensor.Data;
    import javax.microedition.sensor.SensorInfo;
    import javax.microedition.sensor.SensorConnection;
    import javax.microedition.sensor.SensorManager;
    
    public class SensorRaw extends MIDlet {
    
        private SensorConnection sensor;
        Form form;
        Display display;
        
        public void startApp() {
            form = new Form("Available Device Sensors");
            Display.getDisplay(this).setCurrent(form);
            SensorInfo[] infos = SensorManager.findSensors(null, null);
            int noSensors = infos.length;
            if(noSensors == 0) {  
                form.append("No available sensors");
                return;
            }
            for(int i=0; i<noSensors; i++){
                SensorInfo info = infos[i];
                String url = info.getUrl();
                form.append("Sensor Number " + i + "\nSensor URL:" + url+"\n");
                try {
                    sensor = (SensorConnection)Connector.open(url);
                    Data[] data = sensor.getData(1);
                    for(int j=0; j<data.length; j++){
                        int channelInfoDataType = data[j].getChannelInfo().getDataType();
                        form.append("Sensor Channel = "+data[j].getChannelInfo().getName()+"\nSensor type=" + channelInfoDataType +"\n");
                    } 
                    form.append("\n");
                }
                catch(SecurityException se){
                    form.append("No permission to use the sensor!\n");
                }
                catch(Exception e){
                    form.append("Couldn't open sensor " + url+"\n");
                }   
            }
        }
    
        public void destroyApp(boolean par) {}
        public void pauseApp() {}	
    }

Similar Threads

  1. Accelerometer
    By nettserf in forum Symbian
    Replies: 3
    Last Post: 2010-06-09, 10:24
  2. help using accelerometer
    By nettserf in forum Symbian
    Replies: 2
    Last Post: 2010-04-01, 16:42
  3. Accelerometer
    By bukster1000 in forum General Development Questions
    Replies: 17
    Last Post: 2009-04-03, 10:51
  4. Accelerometer
    By mikedeklerk in forum Symbian
    Replies: 32
    Last Post: 2008-04-29, 15:10

Posting Permissions

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