Accessing the Accelerometer

Tutorials with advanced 'difficulty' and more Lines of Code.

Re: Accessing the Accelerometer

Postby edreamz » Wed Sep 15, 2010 11:29 pm

Check the Google dev page for the updates to the new classes, they have comment for each of the deprecated functions and values.
User avatar
edreamz
Junior Developer
Junior Developer
 
Posts: 18
Joined: Fri Aug 06, 2010 2:29 am
Location: U.S

Top

Re: Accessing the Accelerometer

Postby jasra » Thu Oct 14, 2010 7:54 pm

hello,

I m new to android. i m trying to make an applicationb using android, could you please help me hoe to integrate OpenIntents sensor simulator with the code which have mentioned......also could yoy please help me in how to calculate distance using accelerometer.

Jasra
jasra
Once Poster
Once Poster
 
Posts: 1
Joined: Thu Oct 14, 2010 7:48 pm

Re: Accessing the Accelerometer

Postby Lordcorvin » Sun Jan 23, 2011 4:43 am

I tried to run the code and it showed errors all around the code
example:
Sensor.disableSensor(Sensor.SENSOR_ACCELEROMETER);
SENSOR_ACCELEROMETER is underlined and says cannot be resolved or is not a field
what should i do

I'm talking about tutorial on first page of the post
Lordcorvin
Once Poster
Once Poster
 
Posts: 1
Joined: Sun Jan 23, 2011 4:39 am

Re: Accessing the Accelerometer

Postby mshankayi » Sun Mar 20, 2011 7:30 am

see ibm eyes application, it reads accelerometer and rotation sensor and it can be useful :)
mshankayi
Freshman
Freshman
 
Posts: 5
Joined: Sat Mar 19, 2011 8:09 pm

Re: Accessing the Accelerometer

Postby shataj » Wed Apr 06, 2011 12:37 pm

Hello Plusminus,

I am developing an application in which i need to collide to android phones to transfer data between the two devices, similar to the Bump application. My app should detect the collision when it collides with any device and based on the GPS location of those devices the pairing should take place.

I have developed the app using the bump api provided by Bump Technologies, but i want to develop the app without using any such api's.

It will be of great help if you could help me how to detect such collision..
shataj
Once Poster
Once Poster
 
Posts: 1
Joined: Fri Mar 25, 2011 6:13 am

Re: Accessing the Accelerometer

Postby dharan » Wed Jun 08, 2011 5:06 am

hii plusminus do u know how to move an image using accelerometer values.i have already gone through sample code given in android developers site but i didnt understand it properly
Thanks
dharan
Once Poster
Once Poster
 
Posts: 1
Joined: Wed Jun 08, 2011 5:02 am

Top

Re: Accessing the Accelerometer

Postby remo2011 » Tue Jul 12, 2011 10:11 pm

I have read your post many times. Could you tell me if it is possible to use the accelerometer facing towards the user/player and if so, how this is done. My head is in a spin, whether I am using the correct sensor. Help would be appreciated :-)
remo2011
Freshman
Freshman
 
Posts: 2
Joined: Mon Jul 11, 2011 6:40 pm

Re: Accessing the Accelerometer

Postby blazers15 » Tue Aug 14, 2012 3:51 pm

I'm am trying to create an android application that will determine the speed of the phone in one direction using the accelerometer. However im running into some errors when trying to test the app on my phone. its not giving me an error it just won't give me the correct speed. its saying im travelling at 5000+ mph. i will post my code below if anyone can help. thank you for your time

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package net.learn2develop.Speedometer;
  2.  
  3. import java.util.Date;
  4. import java.util.Timer;
  5. import java.util.TimerTask;
  6.  
  7. import android.app.Activity;
  8. import android.content.Context;
  9. import android.hardware.Sensor;
  10. import android.hardware.SensorEvent;
  11. import android.hardware.SensorEventListener;
  12. import android.hardware.SensorManager;
  13. import android.os.Bundle;
  14. import android.os.Handler;
  15. import android.widget.TextView;
  16.  
  17. public class SpeedometerActivity extends Activity {
  18.  
  19.   Handler handler = new Handler();
  20.  
  21.   SensorManager sensorManager;
  22.     TextView myTextView;
  23.  
  24.     float appliedAcceleration = 0;
  25.     float currentAcceleration = 0;
  26.     float velocity = 0;
  27.     Date lastUpdate;    
  28.  
  29.     @Override
  30.     public void onCreate(Bundle icicle) {
  31.       super.onCreate(icicle);
  32.       setContentView(R.layout.main);
  33.  
  34.       myTextView = (TextView)findViewById(R.id.myTextView);
  35.       lastUpdate = new Date(System.currentTimeMillis());
  36.  
  37.       sensorManager = (SensorManager)getSystemService(Context.SENSOR_SERVICE);
  38.       Sensor accelerometer = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
  39.         sensorManager.registerListener(sensorEventListener,
  40.                                        accelerometer,
  41.                                        SensorManager.SENSOR_DELAY_FASTEST);
  42.  
  43.  
  44.       Timer updateTimer = new Timer("velocityUpdate");
  45.       updateTimer.scheduleAtFixedRate(new TimerTask() {
  46.         public void run() {
  47.           updateGUI();
  48.         }
  49.       }, 0, 1000);
  50.     }
  51.  
  52.     private void updateGUI() {
  53.       // Convert from meters per second to miles per hour.
  54.       final double mph = (Math.round(100*velocity / 1.6 * 3.6))/100;
  55.  
  56.       // Update the GUI
  57.       handler.post(new Runnable() {
  58.       public void run() {
  59.           myTextView.setText(String.valueOf(mph) + "mph");
  60.       }
  61.     });
  62.     }
  63.  
  64.   private void updateVelocity() {
  65.       // Calculate how long this acceleration has been applied.
  66.       Date timeNow = new Date(System.currentTimeMillis());
  67.       long timeDelta = timeNow.getTime()-lastUpdate.getTime();
  68.       lastUpdate.setTime(timeNow.getTime());
  69.  
  70.       // Calculate the change in velocity at the
  71.       // current acceleration since the last update.
  72.       float deltaVelocity = appliedAcceleration * (timeDelta/1000);
  73.       appliedAcceleration = currentAcceleration;
  74.  
  75.       // Add the velocity change to the current velocity.
  76.       velocity += deltaVelocity;
  77.     }
  78.  
  79.   //private final SensorListener sensorListener = new SensorListener() {
  80.   private final SensorEventListener sensorEventListener = new SensorEventListener() {
  81.     double calibration = Double.NaN;
  82.  
  83.  
  84.  
  85.       public void onSensorChanged(SensorEvent event) {
  86.         double x = event.values[0];
  87.         double y = event.values[1];
  88.         double z = event.values[2];
  89.  
  90.       double a = Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2) + Math.pow(z, 2));
  91.  
  92.       if (calibration == Double.NaN)
  93.         calibration = a;
  94.       else {
  95.         updateVelocity();
  96.         currentAcceleration = (float)a;
  97.       }
  98.     }
  99.       public void onAccuracyChanged(Sensor sensor, int accuracy) { }
  100.   };
  101. }
Parsed in 0.043 seconds, using GeSHi 1.0.8.4
blazers15
Once Poster
Once Poster
 
Posts: 1
Joined: Tue Aug 14, 2012 3:44 pm

Top
Previous

Return to Advanced Tutorials

Who is online

Users browsing this forum: No registered users and 5 guests