Category Archives: Accelerometer

How to find your Google Plus ID

This is so simple

1. Go to your Google + account (https://plus.google.com/).

2. Click on the Profile icon on the Left.

3. If you look at the URL in the address bar, it should look something like this:

https://plus.google.com/104653270154306099169/posts

4. The long numerical string in the URL is your Google+ ID. Here is CoderzHeaven’s from the URL above:

104653270154306099169/

Google + CoderzHeaven

How to use Accelerometer in Android?

This is a simple post showing how to use accelerometer in android.

This java code prints the values of x,y and z axis in the console.

package com.coderzheaven.pack;

import android.app.Activity;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;

public class AccelerometerTest extends Activity  implements SensorEventListener{
	 private SensorManager sensorManager;
	 double ax,ay,az;   // these are the acceleration in x,y and z axis

    @Override
    public void onCreate(Bundle savedInstanceState) {
    	 super.onCreate(savedInstanceState);
         setContentView(R.layout.main);
         sensorManager=(SensorManager) getSystemService(SENSOR_SERVICE);
         sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL);
    }
    @Override
    public void onAccuracyChanged(Sensor arg0, int arg1) {
    }

    @Override
    public void onSensorChanged(SensorEvent event) {
         if (event.sensor.getType()==Sensor.TYPE_ACCELEROMETER){
             		 ax=event.values[0];
                     ay=event.values[1];
                     az=event.values[2];
                     System.out.println("X = " + ax + ", Y = " + ay +", Z = " + az);
             }
    }
 }

Leave your comments on this post.
Find Coderzheaven on facebook, twitter , google Plus and MySpace for more updates.