Home » Android » android – I want to make google fit in my step Count application-Exceptionshub

android – I want to make google fit in my step Count application-Exceptionshub

Posted by: admin February 24, 2020 Leave a comment

Questions:

I want to make google fit in my step Count application. I saw many tutorials and try to solution problem, but the application isn’t working. in Logcat show this text

Kotlin.NotImplementedError: An operation is not implemented: not implemented
at com.keppnoteapp.MainActivity.onAccuracyChanged(MainActivity.kt:113) 

can anyone help me?

this is my manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.keppnoteapp">

    <uses-permission android:name="android.permission.ACTIVITY_RECOGNITION"/>
    <uses-feature android:name="android.hardware.sensor.stepcounter" android:required="true"/>
    <uses-feature android:name="android.hardware.sensor.stepdetector" android:required="true"/>



    <application 
    .....
    </application>

‘ ‘

class MainActivity : AppCompatActivity(), SensorEventListener {
  var running=false
  var sensorManager:SensorManager?=null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        sensorManager=getSystemService(Context.SENSOR_SERVICE) as SensorManager
    }

‘ ‘

override fun onResume() {
    super.onResume()
    running=true
    var stepsSensor=sensorManager?.getDefaultSensor(Sensor.TYPE_STEP_COUNTER)

    if(stepsSensor==null){
        Toast.makeText(this,"No step Counter Sensor!", Toast.LENGTH_SHORT).show()
    } else{
        sensorManager?.registerListener(this,stepsSensor,SensorManager.SENSOR_DELAY_UI)
    }
}

override fun onPause() {
    super.onPause()
    running=false
    sensorManager?.unregisterListener(this)
}override fun onAccuracyChanged(sensor: Sensor?, accuracy: Int) {
    TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}

override fun onSensorChanged(event: SensorEvent?) {
    TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
    if(running){
        stepsValue.setText(""+event!!.values[0])
    }
}
How to&Answers:

In your code there is a block of TODO(“not implemented”). In kotlin it means that these functions are not implemented and will throw error when called.

Since you have implemented SensorEventListener, so these unimplemented functions are being called.

You can simply remove the TODO(“not implemented”)