[android-developers] Re: Step Counter in Android KitKat

2016-10-04 Thread Naman Arora
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.


[android-developers] Step Counter in Android KitKat

2016-10-04 Thread Naman Arora
Some Android devices works step counter and step detector properly but not 
all android devices, does it is based on gyroscope or accelerometer sensor 
or both.
my phone have accelerometer  sensor but step counter app will not work.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/a398e8bd-28cc-425e-b986-ec7c5cada73e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.