here is the demo app -
package com.example.developer.stepcounter;
import android.app.Activity;
import android.content.Context;
import android.hardware.*;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
import android.widget.Toast;
public class CounterActivity extends Activity implements SensorEventListener {
private SensorManager sensorManager;
private TextView count;
boolean activityRunning;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
count = (TextView) findViewById(R.id.count);
sensorManager = (SensorManager)
getSystemService(Context.SENSOR_SERVICE);
}
@Override
protected void onResume() {
super.onResume();
activityRunning = true;
Sensor countSensor =
sensorManager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER);
if (countSensor != null) {
sensorManager.registerListener(this, countSensor,
SensorManager.SENSOR_DELAY_UI);
} else {
Toast.makeText(this, "Count sensor not available!",
Toast.LENGTH_LONG).show();
}
}
@Override
protected void onPause() {
super.onPause();
activityRunning = false;
// if you unregister the last listener, the hardware will stop
detecting step events
//sensorManager.unregisterListener(this);
}
@Override
public void onSensorChanged(SensorEvent event) {
if (activityRunning) {
count.setText(String.valueOf(event.values[0]));
Log.i("Naman : ", "- " + event.values[0]);
}
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
}
it is not working on Nexus 7 but working on Nexus 5. i don't understand. Thank
you all for help.
--
You received this message because you are subscribed to the Google Groups
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to android-developers+unsubscr...@googlegroups.com.
To post to this group, send email to android-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/android-developers.
To view this discussion on the web visit
https://groups.google.com/d/msgid/android-developers/a5e24677-29e8-4222-a25f-1c49527b1644%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.