• ANDROID_MARS学习笔记_S05_003_传感器采样率及属性


    1.

    2.

     1 import android.app.Activity;
     2 import android.content.Context;
     3 import android.hardware.Sensor;
     4 import android.hardware.SensorEvent;
     5 import android.hardware.SensorEventListener;
     6 import android.hardware.SensorManager;
     7 import android.os.Bundle;
     8 
     9 public class MainActivity extends Activity {
    10 
    11     private SensorManager sensorManager;
    12     @Override
    13     public void onCreate(Bundle savedInstanceState) {
    14         super.onCreate(savedInstanceState);
    15         setContentView(R.layout.activity_main);
    16         
    17         sensorManager = (SensorManager)getSystemService(Context.SENSOR_SERVICE);
    18         Sensor lightSensor = (Sensor)sensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);
    19         
    20         sensorManager.registerListener(new SensorEventListener() {
    21             
    22             public void onSensorChanged(SensorEvent event) {
    23                 String sensorName = event.sensor.getName();
    24                 String sensorVendor = event.sensor.getVendor();
    25                 float resolution = event.sensor.getResolution();
    26                 float power = event.sensor.getPower();
    27                 double timestamp = event.timestamp;
    28                 
    29                 System.out.println("sensor name--->" + sensorName);
    30                 System.out.println("sensor vendor--->" + sensorVendor);
    31                 System.out.println("sensor resolution--->" + resolution);
    32                 System.out.println("sensor power--->" + power);
    33                 System.out.println("timestamp--->" + timestamp);
    34                 
    35             }
    36             
    37             public void onAccuracyChanged(Sensor sensor, int accuracy) {
    38             }
    39         }, lightSensor, SensorManager.SENSOR_DELAY_GAME);
    40     }
    41 }
  • 相关阅读:
    python函数执行超时处理的两种方法
    Flask常用方法函数汇总
    夜神模拟器操作
    简单auto.js自动化处理andorid手机案例
    TCP-三次握手和四次挥手简单概述
    android手机执行shell脚本
    接口测试要测试什么?怎么测?
    python unittest单元测试
    python webdriver 测试框架--数据驱动之Excel驱动
    顺时针打印矩阵
  • 原文地址:https://www.cnblogs.com/shamgod/p/5207441.html
Copyright © 2020-2023  润新知