android开发:传感器的实例light,proximity,accelerometer,SensorManager,Sensor(含步数计算原理)

package com.lanxin.testsensor;

import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;

android开发:传感器操作的实例

text1 = (TextView)findViewById(R.id.text1);//方向传感器
text2 = (TextView)findViewById(R.id.text2);//磁场传感器
text3 = (TextView)findViewById(R.id.text3);//温度传感器
text4 = (TextView)findViewById(R.id.text4);//光感传感器
text5 = (TextView)findViewById(R.id.text5);//压力传感器

mSensor = (SensorManager) getSystemService(SENSOR_SERVICE); //获取Sensor的服务对象

然后在onResume中注册需要开发的传感器监听,代码:
@Override

 
Copyright © 2008-2021 lanxinbase.com Rights Reserved. | 粤ICP备14086738号-3 |