Android SensorManager and sensormanager
Most Android devices have built-in sensors, some of which are hardware-based and some are software-based. Sensors can be used to monitor the 3D Motion and position of a device, and to infer user actions, such as skew, vibration, and rotation, and to monitor changes in the environment around the device.
On the Android platform, we can access and listen to sensors throu
The Android sensor Logoff method is:Public voidUnregisterlistener (Sensorlistener Listener) Use this method to unregister the listener.Today found that this method is not good to use, after the call, the sensor will not be canceled at all.No other cancellation method was found after the search.Debug with debug carefully look at the log, found that every time you enter the sensor interface activity, there are two sensors, which led to the destruction of activity,Unregisterlistener invalid. Cancel
screen is placed horizontally up (Z axis to day), the values of (x, y, z) are (0, 0, 10 );When the mobile phone screen is placed horizontally down (Z axis toward the ground), the values of (x, y, z) are (0, 0,-10 );When the mobile phone screen is placed on the left (X axis to the day), the values of (x, y, z) are (10, 0, 0 );The values of (x, y, z) are (0, 10, 0) when the mobile phone is vertical (Y axis to day );The other analogy is that the day is a positive number, and the day is a negative
); break; case R.id.startMagneticSensor: Intent intent3 = new Intent(getApplicationContext(), MagneticSensor.class); startActivity(intent3); break; default: break; } } }}
First, you must implement the Light function. First, modify the layout as follows:
A textview is implemented to display the illumination intensity. Then modify the LightSensor Code a
-related services. All Sensors must be accessed through SensorMannager. sensorManager = (SensorManager) getSystemService (SENSOR_SERVICE );
2. Get the corresponding Sensor type object through the SensorManager object. In this example, acceleration Sensor is used, and its type is TYPE_ACCELEROMETER,
Sensor = sensorManager
Let's take a look at the sensormanager code.
Sensormanager framework Layer Code
@ Frameworks/base/CORE/Java/Android/hardware/sensormanager. Java
Public sensormanager (lodomainmainloiter) {mmainloiter = mainloiter; // As mentioned above, this is the activity's lodomainsynchronized (slisteners) {If (! Ssensormoduleiniti
-based sensors, which are typically processed two of times. So software-based sensors can also be called virtual or synthetic (synthetic) sensors.
Android has abstracted sensors for each device, where the Sensormanger class is used to control sensors, sensor to describe specific sensors, and sensoreventlistener to monitor changes in sensor values.
(1) Sensormanager class
The instance used to create the sensor service. This class provides a number o
In the previous example, the Android ApiDemos example resolution (61): Graphics-> Compass and the Android ApiDemos example resolution (79): Graphics-> SensorTest involves Sensors.
This example introduces the Sensors usage supported by Android.
SensorManager is used to manage various sensors in Android devices. The method for obtaining the SensorManager instance object is to use getSystemService:
[Java]Priva
Android obtains basic three-axis knowledge
Basic knowledge
Rotation Angle around the Z axis: Azimuth, I call it the north-facing corner (the north-facing direction of the compass)
Rotation Angle around the X axis: Pitch.
Rotation Angle around the Y axis: Roll, I call it the left and right corner.
Solution 1: Magnetic Field Sensor + acceleration sensor (recommended)
Step 1: Obtain sensor system services
Private SensorManager
Android implements the shake function, and android implements the shake function.
To implement the "Shake" function, it is actually very simple. It is to detect the mobile phone's gravity sensor. The specific implementation code is as follows:
1. Add operation permissions in AndroidManifest. xml
II. Implementation Code
[Java]View plaincopy
Package com. xs. test;
Import android. app. Activity;
Import android. hardware. Sensor;
Import android. hardware. SensorEvent;
Import android. hardw
For convenience, Roboguice provides "standard injection" support for some of the objects or services commonly used on the Android platform. For example, you do not need to use (Sensormanager) Getsystemservice (Sensor_service) to obtain a Sensormanger instance and use the @inject tag directly
@Inject Sensormanager Sensormanager;
Roboguice automatically injects t
, int32_t MS );Int (* wake) (struct sensors_control_device_t * dev );[Data]Int (* data_open) (struct sensors_data_device_t * dev, int fd );Int (* data_close) (struct sensors_data_device_t * dev );Int (* poll) (struct sensors_data_device_t * dev, sensors_data_t * data );[Module]Int (* get_sensors_list) (struct sensors_module_t * module, struct sensor_t const ** list );
The SensorService is responsible for the state control of Sensor at the JAVA layer. Its java code and JNI code are located:Framew
The above has already introduced the porting process of android temperature sensor. The code page has been posted to everyone. Now we can write an APK for testing. The code is very simple, and the interface is very simple and ugly. Haha, don't mind. This aok is only used for testing. I will not introduce it more here and paste the Code directly.Package com. android. jay. sensor1;Import android. app. Activity;Import android. hardware. Sensor;Import android. hardware. SensorEvent;Import android. h
following hardware-oriented functions.
Table 1. Hardware-oriented features provided by the android SDKFeature descriptionAndroid. Hardware. Camera allows apps to interact with cameras. You can take photos, get preview screen images, and modify the parameters used to manage camera operations.Android. Hardware. sensormanager class that allows access to Android platform sensors. Not all devices equipped with Android support all sensors in
Implementation of android level (use of direction sensors)
A long time ago, I have studied the Sensor. TYPE_ORIENTATION. According to my own practice, I have rewritten the two online leveling examples, re-encapsulated and used them, and finally used them in projects.1. Preface
The following is a sensor from the Android sensor.
Generally, in the android system, the TYPE_ORIENTATION constant is used in the api to obtain the orientation information of the mobile phone. You can get the direction se
and software-based. Hardware-based sensors are often implemented through physical components. They usually obtain data by measuring attributes of special environments, such as changes in gravity acceleration, geomagnetic intensity, or azimuth angle. Software-based sensors do not rely on physical devices, though they mimic hardware-based sensors. Software-based sensors usually obtain data through one or more hardware sensors, and sometimes call virtual sensors or artificial sensors, linear accel
Android --- 57 --- sensor, android Sensor
The Android system provides support for sensors.Developing an application sensor is simple. You only need to register a listener for the specified listener.
Steps:1. Call the getSystemService (Context. SENSOR_SERVICE) method of Context to obtain the SensorManager object. The SensorManager object represents the system's sensor management service.2. Call the getdefase
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.