I have implemented a program that is able to get the distance and direction of other person. Now I want to show this information by a dynamic arrow pointing to the other person direction (like a needle) and as the user moves his phone, the arrow will change its direction to still point the other person direction.
So, it is to be implemented like this: an activity will pass the direction (of the other person) in degrees (0<= x <=360) to another activity whose task is to graphically show the arrow.
I know how to know the azimuth value and thereby calculate the degree of rotation of arrow for a particular direction value (x). I know the logic of implementation but I have no knowledge about graphic, animation etc.
Any quick Help is highly appreciated.
This is the code which meets the requirement. I dont know but a better solution may exists :-
package com.visd.giraffe;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.graphics.drawable.BitmapDrawable;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.util.Log;
import android.widget.ImageView;
import android.widget.TextView;
public class arrowhandler extends Activity implements SensorEventListener {
Matrix mtx = new Matrix();
ImageView img;
Bitmap bmp ;
int w,h;
float d = 0;
float oldval = 0,currentrot = 0, rotate = 0,senserotat;
private SensorManager sensorManager = null;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get a reference to a SensorManager
sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
setContentView(R.layout.mmmain);
String[] arrs = getIntent().getExtras().getStringArray("SMSR");
int degr = arrs[0].indexOf("Dgr:");
String msgg = "Location of " + arrs[0].substring((arrs[0].indexOf("nosss"))+5) + "\n\n" + arrs[0].substring(0, degr);
Log.d("AOA",arrs[0].substring(degr+4));
d = (Float.valueOf(arrs[0].substring(degr+4, arrs[0].indexOf("nosss")))).floatValue();
Log.d("AOA dv", Float.toString(d));
if (d>0)
{
d = d+180;
}
else if (d<0)
{
d = 180 - (Math.abs(d));
}
Log.d("AOA dv", "2" + Float.toString(d));
Log.d("AOA",Float.toString(d));
TextView t = (TextView) findViewById(R.id.textView1);
t.setText(msgg);
img=(ImageView)findViewById(R.id.imageView1);
bmp = BitmapFactory.decodeResource(getResources(), R.drawable.bluearrow);
// Getting width & height of the given image.
w = bmp.getWidth();
h = bmp.getHeight();
}
// This method will update the UI on new sensor events
public void onSensorChanged(SensorEvent sensorEvent) {
synchronized (this) {
if (sensorEvent.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
}
if (sensorEvent.sensor.getType() == Sensor.TYPE_ORIENTATION) {
senserotat = d-sensorEvent.values[0];
if (senserotat < 0)
{
senserotat = 360 - (Math.abs(senserotat));
}
rotate = (360-currentrot)+senserotat;
if (rotate>360)
{
rotate = rotate-360;
}
mtx.postRotate(rotate);
// Rotating Bitmap
Bitmap rotatedBMP = Bitmap.createBitmap(bmp, 0, 0, w, h, mtx, true);
BitmapDrawable bmd = new BitmapDrawable(rotatedBMP);
img.setImageDrawable(bmd);
currentrot = senserotat;
//Log.d("TTTT", Float.toString(sensorEvent.values[0]));
}
}
}
public void onAccuracyChanged(Sensor arg0, int arg1) {
// TODO Auto-generated method stub
}
#Override
protected void onResume() {
super.onResume();
// Register this class as a listener for the accelerometer sensor
sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL);
// ...and the orientation sensor
sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION), SensorManager.SENSOR_DELAY_NORMAL);
}
#Override
protected void onStop() {
// Unregister the listener
sensorManager.unregisterListener(this);
super.onStop();
}
}
Related
I am a beginner at android programming and I have come up with some progress on getting the sensor data (Source code below). Can someone help me with detecting how fast my Android device is moving using these information? For example if I am moving the device fast, it will give me like 10, and if I am moving it slowly, I will get like 1. Aside from accelerometer, all other sensors are also OK for me.
package course.examples.Sensors.ShowValues;
import android.app.Activity;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.widget.TextView;
public class SensorRawAccelerometerActivity extends Activity implements
SensorEventListener {
private static final int UPDATE_THRESHOLD = 500;
private SensorManager mSensorManager;
private Sensor mAccelerometer;
private TextView mXValueView, mYValueView, mZValueView;
private long mLastUpdate;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mXValueView = (TextView) findViewById(R.id.x_value_view);
mYValueView = (TextView) findViewById(R.id.y_value_view);
mZValueView = (TextView) findViewById(R.id.z_value_view);
// Get reference to SensorManager
mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
// Get reference to Accelerometer
if (null == (mAccelerometer = mSensorManager
.getDefaultSensor(Sensor.TYPE_ACCELEROMETER)))
finish();
}
// Register listener
#Override
protected void onResume() {
super.onResume();
mSensorManager.registerListener(this, mAccelerometer,
SensorManager.SENSOR_DELAY_UI);
mLastUpdate = System.currentTimeMillis();
}
// Unregister listener
#Override
protected void onPause() {
mSensorManager.unregisterListener(this);
super.onPause();
}
// Process new reading
#Override
public void onSensorChanged(SensorEvent event) {
if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
long actualTime = System.currentTimeMillis();
if (actualTime - mLastUpdate > UPDATE_THRESHOLD) {
mLastUpdate = actualTime;
float x = event.values[0], y = event.values[1], z = event.values[2];
mXValueView.setText(String.valueOf(x));
mYValueView.setText(String.valueOf(y));
mZValueView.setText(String.valueOf(z));
}
}
}
#Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
// N/A
}
}
Accelerometers measure change in speed (acceleration), not speed itself. If you are looking for short distances you are out of luck. Long distances you can poll this data from the GPS which gives you a heading and average velocity.
I'm learning Android programming.
So I managed to implement a simple app that rolls a ball over the screen if you tilt yout phone. But right now it is as simple as:
if roll > 0 then xpos++ else xpos-- end and the same for ypos.
So I want to calculate a more exact direction and also I would like the ball to roll faster the more the phone is tilting.
So if I know the tilt in the roll direction and the pitch direction, how do I calculate the direction and speed of the ball?
Here is how:
package benyamephrem.tiltball;
import android.graphics.Point;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import java.util.Timer;
import java.util.TimerTask;
import android.app.Activity;
import android.os.Handler;
import android.view.Display;
import android.view.Window;
import android.view.WindowManager.LayoutParams;
import android.widget.FrameLayout;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorManager;
import android.content.Context;
import android.content.res.Configuration;
import android.hardware.SensorEventListener;
import android.widget.Toast;
public class TiltBall extends ActionBarActivity {
BallView mBallView = null;
Handler RedrawHandler = new Handler(); //so redraw occurs in main thread
Timer mTmr = null;
TimerTask mTsk = null;
int mScrWidth, mScrHeight;
android.graphics.PointF mBallPos, mBallSpd;
#Override
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE); //hide title bar
//set app to full screen and keep screen on
getWindow().setFlags(0xFFFFFFFF, LayoutParams.FLAG_FULLSCREEN | LayoutParams.FLAG_KEEP_SCREEN_ON);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tilt_ball);
//create pointer to main screen
final FrameLayout mainView = (android.widget.FrameLayout) findViewById(R.id.main_view);
//get screen dimensions
Display display = getWindowManager().getDefaultDisplay();
mScrWidth = display.getWidth();
mScrHeight = display.getHeight();
mBallPos = new android.graphics.PointF();
mBallSpd = new android.graphics.PointF();
//create variables for ball position and speed
mBallPos.x = mScrWidth / 2;
mBallPos.y = mScrHeight / 5;
mBallSpd.x = 0;
mBallSpd.y = 0;
//create initial ball
mBallView = new BallView(this, mBallPos.x, mBallPos.y, 75);
mainView.addView(mBallView); //add ball to main screen
mBallView.invalidate(); //call onDraw in BallView
//listener for accelerometer, use anonymous class for simplicity
((SensorManager) getSystemService(Context.SENSOR_SERVICE)).registerListener(
new SensorEventListener() {
#Override
public void onSensorChanged(SensorEvent event) {
//set ball speed based on phone tilt (ignore Z axis)
//***Change speed here by multiplying event values by bigger numbers***
mBallSpd.x = -event.values[0] * (30/10);
mBallSpd.y = event.values[1] * (30/10);
//timer event will redraw ball
}
#Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
} //ignore
},
((SensorManager) getSystemService(Context.SENSOR_SERVICE))
.getSensorList(Sensor.TYPE_ACCELEROMETER).get(0),
SensorManager.SENSOR_DELAY_NORMAL);
//listener for touch event
mainView.setOnTouchListener(new android.view.View.OnTouchListener() {
public boolean onTouch(android.view.View v, android.view.MotionEvent e) {
//set ball position based on screen touch
mBallPos.x = e.getX();
mBallPos.y = e.getY();
//timer event will redraw ball
return true;
}
});
} //OnCreate
//listener for menu button on phone
#Override
public boolean onCreateOptionsMenu(Menu menu) {
menu.add("Exit"); //only one menu item
return super.onCreateOptionsMenu(menu);
}
//listener for menu item clicked
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
if (item.getTitle() == "Exit") //user clicked Exit
finish(); //will call onPause
return super.onOptionsItemSelected(item);
}
//For state flow see http://developer.android.com/reference/android/app/Activity.html
#Override
public void onPause() //app moved to background, stop background threads
{
mTmr.cancel(); //kill\release timer (our only background thread)
mTmr = null;
mTsk = null;
super.onPause();
}
#Override
public void onResume() //app moved to foreground (also occurs at app startup)
{
//create timer to move ball to new position
mTmr = new Timer();
mTsk = new TimerTask() {
public void run() {
//if debugging with external device,
// a log cat viewer will be needed on the device
Log.d("TiltBall", "Timer Hit - " + mBallPos.x + ":" + mBallPos.y);
//move ball based on current speed
mBallPos.x += mBallSpd.x;
mBallPos.y += mBallSpd.y;
//if ball goes off screen, reposition to opposite side of screen
if (mBallPos.x > mScrWidth) mBallPos.x = 0;
if (mBallPos.y > mScrHeight) mBallPos.y = 0;
if (mBallPos.x < 0) mBallPos.x = mScrWidth;
if (mBallPos.y < 0) mBallPos.y = mScrHeight;
//update ball class instance
mBallView.x = mBallPos.x;
mBallView.y = mBallPos.y;
//redraw ball. Must run in background thread to prevent thread lock.
RedrawHandler.post(new Runnable() {
public void run() {
mBallView.invalidate();
}
});
}
}; // TimerTask
mTmr.schedule(mTsk, 10, 10); //start timer
super.onResume();
} // onResume
#Override
public void onDestroy() //main thread stopped
{
super.onDestroy();
//wait for threads to exit before clearing app
System.runFinalizersOnExit(true);
//remove app from memory
android.os.Process.killProcess(android.os.Process.myPid());
}
//listener for config change.
//This is called when user tilts phone enough to trigger landscape view
// we want our app to stay in portrait view, so bypass event
#Override
public void onConfigurationChanged(Configuration newConfig)
{
super.onConfigurationChanged(newConfig);
}
} //TiltBallActivity
Here is the BallView class;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.view.View;
public class BallView extends View {
public float x;
public float y;
private final int r;
private final Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
//construct new ball object
public BallView(Context context, float x, float y, int r) {
super(context);
//color hex is [transparncy][red][green][blue]
mPaint.setColor(0xFF1325E0); //not transparent. color is blue
this.x = x;
this.y = y;
this.r = r; //radius
}
//qcalled by invalidate()
#Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawCircle(x, y, r, mPaint);
}
public int getRadius(){
return r;
}
}
This is not my code but I forgot its source so credits to whoever made it. I am using it for a current project I'm working on.
I have developed a step detection app suing android. There I have filtered my sensor data(accelerometer data x, y, z) and need to smooth the signal with 5-point smoothing algorithm. I saw it in a research paper. I have search about that algorithm and couldn't find a proper resource which can use with android(java). Any one can give me a help that hove can I achieve this.
here is my code to get accelerometer data and filtered with low-pass-filter
package com.android.gait;
import org.achartengine.GraphicalView;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.view.Menu;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
public class MainActivity extends Activity implements SensorEventListener{
static final float ALPHA = 0.15f;
private int count=0;
private static GraphicalView view;
private LineGraph line = new LineGraph();
private static Thread thread;
private SensorManager mSensorManager;
private Sensor mAccelerometer;
TextView title,tv,tv1,tv2;
RelativeLayout layout;
private double a;
static float m = 0;
private float p,q,r;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//get the sensor service
mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
//get the accelerometer sensor
mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
//get layout
layout = (RelativeLayout)findViewById(R.id.relative);
LinearLayout layout = (LinearLayout) findViewById(R.id.layoutC);
view= line.getView(this);
layout.addView(view);
//get textviews
title=(TextView)findViewById(R.id.name);
tv=(TextView)findViewById(R.id.xval);
tv1=(TextView)findViewById(R.id.yval);
tv2=(TextView)findViewById(R.id.zval);
thread = new Thread(){
int iniX=0;
public void run()
{
while(true)
{
try {
Thread.sleep(1);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
iniX=+1;
line.addNewPoint(iniX,m);
view.repaint();
}
}
};
thread.start();
}
public final void onAccuracyChanged(Sensor sensor, int accuracy)
{
// Do something here if sensor accuracy changes.
}
#Override
public final void onSensorChanged(SensorEvent event)
{
count=+1;
// Many sensors return 3 values, one for each axis.
float x = event.values[0];
float y = event.values[1];
float z = event.values[2];
float[] first={x,y,z};
float[] larst={p,q,r};
larst= lowPass(first,larst);
//double FY= b.Filter(y);
//double FZ= b.Filter(z);
//get merged value
m = (float) Math.sqrt(larst[0]*larst[0]+larst[1]*larst[1]+larst[2]*larst[2]);
//display values using TextView
title.setText(R.string.app_name);
tv.setText("X axis" +"\t\t"+larst[0]);
tv1.setText("Y axis" + "\t\t" +larst[1]);
tv2.setText("Z axis" +"\t\t" +larst[2]);
}
#Override
protected void onResume()
{
super.onResume();
mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_NORMAL);
}
#Override
protected void onPause()
{
super.onPause();
mSensorManager.unregisterListener(this);
}
public void LineGraphHandler(View view){
}
//Low pass filter
protected float[] lowPass( float[] input, float[] output ) {
if ( output == null ) return input;
for ( int i=0; i<input.length; i++ ) {
output[i] = output[i] + ALPHA * (input[i] - output[i]);
}
return output;
}
/*#Override
public void onStart(){
super.onStart();
view= line.getView(this);
setContentView(view);
}*/
}
An n-point smoothing algorithm simply returns the average of the currently-stored n data points.
In your case, n=5. Suppose you have already stored 5 data points kept in order of oldest to newest:
Current data: 1, 3, 5, 4, 9 (where the most recently read data was 9)
Suppose further that you now read in the data point 7. All the data is now pushed by one position to the left, with the oldest data point being removed completely. The data points now are:
Current data: 3, 5, 4, 9, 7
Now calculate the average of those values, (3+5+4+9+7)/5 = 5.6, which is the new smoothed value. Every time you add a new value, you should calculate and read a new smoothed value. The stream of the values you read are all smoothed.
Note that, in fact, a discrete FIR filter (which you mentioned) performs the exact smoothing (averaging) operation if you are performing convolution between the data points and coefficients of 1/5. That is, the averaging that I described above, (3+5+4+9+7)/5, is exactly the same as a convolution of (3, 5, 4, 9, 7) and (1/5, 1/5, 1/5, 1/5, 1/5). The convolution computation would be 3 * 1/5 + 5 * 1/5 + 4 * 1/5 + 9 * 1/5 + 7 * 1/5 = 5.6
Hi my app is on sensors and I am not able to find any other color if i shake it.I have provided only two colors in if else loop. But if in want to add some more colors then what should i add. What is the solution.Please help me in this problem.
package com.sensortestactivity;
import android.app.Activity;
import android.graphics.Color;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Toast;
public class SensorTestActivity extends Activity implements SensorEventListener {
private SensorManager sensorManager;
private Boolean color = false;
private View view;
private long lastUpdate;
// -- CALLED WHEN THE ACTIVITY IS FIRST CREATED --//
#Override
public void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
view = findViewById(R.id.textView);
view.setBackgroundColor(Color.GREEN);
sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
sensorManager.registerListener(this,
sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
SensorManager.SENSOR_DELAY_NORMAL);
lastUpdate = System.currentTimeMillis();
}
#Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
#Override
public void onSensorChanged(SensorEvent event) {
if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
getAccelerometer(event);
}
}
private void getAccelerometer(SensorEvent event) {
float[] values = event.values;
// -- MOVEMENT --
float x = values[0];
float y = values[1];
float z = values[2];
float accelerationSquareRoot = (x * x + y * y + z * z)
/ (SensorManager.GRAVITY_EARTH * SensorManager.GRAVITY_EARTH);
long actualTime = System.currentTimeMillis();
if (accelerationSquareRoot >= 2) {
if (actualTime - lastUpdate < 200) {
return;
}
lastUpdate = actualTime;
Toast.makeText(this, "DEVICE WAS SHUFFELED", Toast.LENGTH_SHORT)
.show();
if (color) {
view.setBackgroundColor(Color.GREEN);
} else {
view.setBackgroundColor(Color.RED);
}
color = !color;
}
}
#Override
protected void onPause() {
super.onPause();
sensorManager.unregisterListener(this);
}
#Override
protected void onResume() {
super.onResume();
// -- REGISTER THIS CLASS AS A LISTENER FOR THE ORIENTATION AND
// ACCELEROMETER SENSORS --
sensorManager.registerListener(this,
sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
SensorManager.SENSOR_DELAY_NORMAL);
}
}
you may use
view.setBackgroundColor(HEXVALUE);
The hexvalue is used like this: 0xAARRGGBB
AA = alpha channel
RR = red channel
GG = green channel
BB = blue channel
A valid color would be: 0xFFFF0000 which will create red
Another valid color: 0xFFF0F0F0
for hex numbers you should take a look at wikipedia. http://en.wikipedia.org/wiki/Hexadecimal
You can randomly set the color using a random number generator.
Math.random() * 17
This will give you integer values starting with 0 and ending at 16. You just need to calc those to hex:
0 = 0
1 = 1
2 = 2
...
9 = 9
10 = A
11 = B
...
16 = F
I am working with accelerometer for android, I do not understand why the three axis for them which I have assigned to mSensorX, mSensorY and mSensorZ are labelled as unused when I have used them in the onSensorChange, could someone please help me understand this.
package com.example.imageaccel;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.widget.TextView;
public class ImageAccelActivity extends Activity implements SensorEventListener {
/** Called when the activity is first created. */
TextView x, y, z;
private float mSensorX;
private float mSensorY;
private float mSensorZ;
private Bitmap car;
private SensorManager sm = null;
// Bitmap car1;
// float x1, y1, z1, sensorX, sensorY, sensorZ;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
x = (TextView)findViewById(R.id.x_axis);
y = (TextView)findViewById(R.id.y_axis);
z = (TextView)findViewById(R.id.z_axis);
SensorManager sm = (SensorManager)getSystemService(Context.SENSOR_SERVICE);
if (sm.getSensorList(Sensor.TYPE_ACCELEROMETER).size() !=0){
Sensor s = sm.getSensorList(Sensor.TYPE_ACCELEROMETER).get(0);
sm.registerListener(this, s, SensorManager.SENSOR_DELAY_NORMAL);
}
}
#Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
sm.registerListener(this, sm.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),SensorManager.SENSOR_DELAY_NORMAL);
}
#Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
sm.unregisterListener(this);
super.onPause();
}
#Override
public void onAccuracyChanged(Sensor arg0, int arg1) {
// TODO Auto-generated method stub
}
#Override
public void onSensorChanged(SensorEvent ev) {
// TODO Auto-generated method stub
if(ev.sensor.getType()==Sensor.TYPE_ACCELEROMETER){
mSensorX = ev.values[0];
mSensorY = ev.values[1];
mSensorZ = ev.values[2];
}
}
protected void onDraw(Canvas canvas) {
/*
* draw the background
*/
canvas.drawBitmap(car, 0, 0, null);
}
}
You're setting them to a value but that's only half the story. The complaint is most likely that you're never using them after that. It's similar to the C code:
int main (void) {
int a = 1;
return 0;
}
While that compiles and runs fine, you do get a warning (using gcc -Wall) that:
warning: unused variable 'a'
Quick way to check this theory, put a:
System.out.println (mSensorX + "," + mSensorY + "," + mSensorZ);
(or some other sort of use) following the setting and see if the warning disappears.
I think there is a warning because of the if statement there..In some cases they won't be used and hence the warning..That's my opinion:)