Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3604236
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:58:21+00:00 2026-05-18T20:58:21+00:00

I gathered plenty of samples and tutorials on the matter but once I implement

  • 0

I gathered plenty of samples and tutorials on the matter but once I implement my own version or even just copy the code straight off, I cannot get any values to show up in my log.

I think I am missing one important part but I cannot seem to figure it out.

public class Accelerometer extends Activity {

    SensorManager sensorManager;
    Sensor accelerometer;

    private SensorEventListener sensorEventListener = new SensorEventListener() {

        public void onAccuracyChanged(Sensor sensor, int accuracy) {

        }

        public void onSensorChanged(SensorEvent event) {

            float x = event.values[0];
            float y = event.values[1];
            float z = event.values[2];
            update(x, y, z);
        }
    };

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        sensorManager = (SensorManager)getSystemService(SENSOR_SERVICE);
        accelerometer = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    }

    public void update(float x, float y, float z) {

        Log.v("semajhan", "x: " + x + " y: " + y + " z: " + z);
    }

    protected void onResume() {
        super.onResume();
        sensorManager.registerListener(sensorEventListener, accelerometer, SensorManager.SENSOR_DELAY_NORMAL);
    }

    protected void onPause() {
        super.onPause();
        sensorManager.unregisterListener(sensorEventListener);
    }
}

My problem seems to be that I do not know how to really access the accelerometer.

Once I can get these values, I can move forward but I need to understand this first.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T20:58:21+00:00Added an answer on May 18, 2026 at 8:58 pm

    Your code seems ok to me. It is similar to working examples I also used to fetch the sensor data. One thing may be problematic. Are you sure you have sensor of that type on your device?

    To check that use

    public List<Sensor> getSensorList (int type) 
    

    function of SensorManager. You can get full list of sensors available on your device if you use type = Sensor.TYPE_ALL in function call, and go through all list elements.

    UPDATE:

    Tried your code. It is fully functional. Issue is that display of traces is disabled on your Nexus. To enable traces go to Settings->Applications->Development and check option USB debugging. Without that you get no traces.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In Maya, I have a list of constraints gathered by the following code. I
Im pretty new to REST but as far as i have gathered i understand
This is my piece of code that i gathered from here . private unsafe
Right now we have all our code gathered in main.lua. We don't want to
I've noticed that hard coded Top/left positions (gathered via code) from the avd do
I cant tell If I'm just not getting what these 2 things are but
So I gathered from different places on the internet some code to export a
I tried following the advice gathered from Google searches but I am not able
As far as I've gathered (read: measured), building the configuration and the sessionfactory by
I am new to silverlight and from what I gathered there isnt any direct

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.