我有步进计数传感器的代码,但我在我的设备上运行此代码,它不工作
override fun init_events() {
sensoreManager=getSystemService(Context.SENSOR_SERVICE) as SensorManager
if(sensoreManager!!.getDefaultSensor(Sensor.TYPE_STEP_COUNTER)!=null)
{
sensor=sensoreManager!!.getDefaultSensor(Sensor.TYPE_STEP_COUNTER)
running=true
showToastMessage("yes")
}else{
showToastMessage("no")
running=false
}
}
override fun onAccuracyChanged(sensor: Sensor?, accuracy: Int) {
Log.i("TEST_TEST","ssssssssssss")
}
@SuppressLint("SetTextI18n")
override fun onSensorChanged(event: SensorEvent?) {
Log.i("TEST_TEST","ssssssssssss")
if(event!!.sensor==sensor)
showToastMessage("movment")
}
override fun onResume() {
Log.i("TEST_TEST","f RESume")
super.onResume()
if(sensoreManager!!.getDefaultSensor(Sensor.TYPE_STEP_COUNTER)!=null){
sensoreManager!!.registerListener(this,sensor,SensorManager.SENSOR_DELAY_FASTEST)
Log.i("TEST_TEST","not null")}
else{
Log.i("TEST_TEST","null")
}
}
override fun onPause() {
Log.i("TEST_TEST","f onPause")
super.onPause()
if(sensoreManager!!.getDefaultSensor(Sensor.TYPE_STEP_COUNTER)!=null)
sensoreManager!!.unregisterListener(this,sensor)
}
这个代码有什么问题我的小米Note9Pro
1条答案
按热度按时间qzwqbdag1#
在这段代码中,你必须接受android10的权限