Android Learning notes-get sensor information

Source: Internet
Author: User

Original link: http://www.open-open.com/lib/view/open1423812538326.html

Android 4.4 (API level 19) supports the following sensors: (note that not all phones support all sensors)

type_accelerometer Acceleration Sensor, Unit is M/S2, measure the Accelerometer type value (sensor type) applied to the device x, Y, Z axis:1 (0x00000001) Type_ambient_temperature temperature sensor, Unit is the ℃ sensor type value (sensor type):(0x0000000dType_game_rotation_vector Game Action sensor, no electromagnetic interference affects the sensor type value:(0x0000000ftype_geomagnetic_rotation_vector geomagnetic rotation vector sensor, which provides the rotation vector of the phone, while the phone is in hibernation, it can still record the device's azimuth sensor type value (sensor type):(0x00000014) type_gravity gravity sensor, Unit m/s2, measure the value of the gravity sensor type (sensor type) applied to the device x, Y, Z axis:9 (0x00000009) Type_gyroscope Gyroscope sensor, Unit is RAD/s, measuring device x, Y, z three-axis angular acceleration sensor type value (sensor type):4 (0x00000004The type_gyroscope_uncalibrated Gyro sensor is not calibrated to provide raw, calibrated, compensated gyroscope data for post-processing and fusion positioning data sensor type values (sensor type):(0x00000010Type_light light sensor, unit LX, detects the ambient light intensity sensor type value (sensor type):5 (0x00000005) type_linear_acceleration linear accelerometer, Unit m/S2, the sensor is the data sensor type value that gets the effect of getting the accelerometer to remove the gravitational force of the Sensor (sensor type):Ten (0x0000000aType_magnetic_field Magnetic sensor, Unit is UT (micro-Tesla), measuring three physical axes (x, y, z) of the magnetic field sensor type value (sensor type):2 (0x00000002The type_magnetic_field_uncalibrated magnetic sensor is not calibrated to provide a raw, non-calibrated magnetic field data sensor type value (sensor type):(0x0000000e) type_orientation direction sensor, measuring the rotation angle sensor type value of the device around three physical axes (x, Y, z):3 (0x00000003The type_pressure pressure sensor, in units of hpa (kpa), returns the pressure sensor type value in the current environment (sensor type):6 (0x00000006The type_proximity distance sensor, in cm, is used to measure the distance sensor type value of an object to the screen:8 (0x00000008) type_relative_humidity Humidity sensor, Unit is%, to measure the relative humidity sensor type value of the ambient environment (transducer type):(0x0000000c) type_rotation_vector rotation vector sensor, rotation vector represents the device's direction sensor type value (sensor type):One (0x0000000b) Type_significant_motion Special Action trigger sensor type value (transducer type):(0x00000011) Type_step_counter Step sensor sensor Type value (sensor):(0x00000013Type_step_detector Walk detection sensor, the user triggers the event sensor type value each step of the way (sensor type):(0x00000012) The type_temperature temperature sensor, which has been replaced by the Type_ambient_temperature sensor type value, is now:7 (0x00000007)

Get a list of phone sensor information

Importjava.util.List;ImportAndroid.os.Bundle;ImportAndroid.annotation.SuppressLint;Importandroid.app.Activity;ImportAndroid.content.Context;ImportAndroid.hardware.Sensor;ImportAndroid.hardware.SensorManager;ImportAndroid.view.Menu; Public classMainactivityextendsActivity {@Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);         Setcontentview (R.layout.activity_main);    Getsensorlist (); } @SuppressLint ("Newapi")    Private voidgetsensorlist () {//Get the sensor managerSensormanager Sensormanager =(Sensormanager) Getsystemservice (Context.sensor_service); //get the full list of sensorslist<sensor> sensors =sensormanager.getsensorlist (Sensor.type_all); //Print each sensor informationStringBuilder Strlog =NewStringBuilder (); intIIndex = 1;  for(Sensor item:sensors) {strlog.append (IIndex+ "."); Strlog.append ("Sensor Type-" + item.gettype () + "\ r \ n"); Strlog.append ("Sensor Name-" + item.getname () + "\ r \ n"); Strlog.append ("Sensor Version-" + item.getversion () + "\ r \ n"); Strlog.append ("Sensor Vendor-" + item.getvendor () + "\ r \ n"); Strlog.append ("Maximum Range-" + item.getmaximumrange () + "\ r \ n"); Strlog.append ("Minimum Delay-" + item.getmindelay () + "\ r \ n"); Strlog.append ("Power-" + item.getpower () + "\ r \ n"); Strlog.append ("Resolution-" + item.getresolution () + "\ r \ n"); Strlog.append ("\ r \ n"); IIndex++;    } System.out.println (Strlog.tostring ()); } @Override Public BooleanOncreateoptionsmenu (Menu menu) {//inflate the menu; This adds items to the action bar if it is present.getmenuinflater (). Inflate (R.menu.activity_main, menu); return true; } }

Android Learning notes-get sensor information

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.