to display the openintent accelerometer value on the emulato

News, information, contests and special event announcements from members of the anddev.org community.

to display the openintent accelerometer value on the emulato

Postby anu » Mon Jan 04, 2010 10:55 am

can anybody help me ......

I have to access the values on the screen of the openintent accelerometer. I am able to get the get the accelerometer but I want to display the values of the openintent accelerometer on the screen without getting the interface....I am using the below code ...could anybody help me in this ...


package com.test1;

import org.openintents.hardware.SensorManagerSimulator;



import org.openintents.provider.Hardware;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.hardware.SensorListener;
import android.widget.TextView;





public class test1 extends Activity {

private TextView mTxtView;

private SensorManager sm;


/**private SensorEventListener mySensorEventListener;*/
/** Called when the activity is first created. */


@Override
public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

mTxtView = new TextView(this);
setContentView(mTxtView);
/** setContentView(R.layout.main);*/

Hardware.mContentResolver = getContentResolver();

/**sm = (SensorManager)getSystemService(Context.SENSOR_SERVICE);*/

sm = (SensorManager) new SensorManagerSimulator((SensorManager)
getSystemService(SENSOR_SERVICE));



/** Intent intent = new Intent(Intent.ACTION_VIEW,
Hardware.Preferences.CONTENT_URI);
startActivity(intent); */

/** sm.unregisterListener(mGraphView); */

SensorManagerSimulator.connectSimulator();

sm.registerListener( mySensorListener,
Sensor.TYPE_ACCELEROMETER |
Sensor.TYPE_MAGNETIC_FIELD |
Sensor.TYPE_ORIENTATION,
SensorManager.SENSOR_DELAY_UI);

/** mTxtView = new TextView(this);
setContentView(mTxtView); */
}

public void updateTV(float p_x, float p_y, float p_z)
{
mTxtView.setText("x: "+p_x+", y: "+p_y+", z: "+p_z);

}

private final SensorListener mySensorListener = new SensorListener() {

public void onSensorChanged(int sensor, float[] values) {
if (sensor == Sensor.TYPE_ACCELEROMETER)
{
float x = values[SensorManager.DATA_X];
float y = values[SensorManager.DATA_Y];
float z = values[SensorManager.DATA_Z];
updateTV(x, y , z);
}
}
public void onAccuracyChanged(int sensor, int accuracy) {}
};

/**private final SensorEventListener mSensorListener = new SensorEventListener() {

public void onSensorChanged(SensorEvent se)
{
float x = se.values[0];
float y = se.values[1];
float z = se.values[2];
updateTV(x, y , z);
}

public void onAccuracyChanged(Sensor sensor, int accuracy) {}
}; */



@Override
protected void onResume() {
super.onResume();
sm.registerListener(mySensorListener,
Sensor.TYPE_ACCELEROMETER |
Sensor.TYPE_MAGNETIC_FIELD |
Sensor.TYPE_ORIENTATION,
SensorManager.SENSOR_DELAY_UI);
}

}



Regards
Anshu
anu
Freshman
Freshman
 
Posts: 2
Joined: Sat Jan 02, 2010 6:49 am

Top

Return to Open News

Who is online

Users browsing this forum: No registered users and 1 guest