1page.title=Sensors 2pdk.version=1.0 3doc.type=porting 4@jd:body 5 6<div id="qv-wrapper"> 7<div id="qv"> 8<h2>In this document</h2> 9<a name="toc"/> 10<ul> 11<li><a href="#androidSensorsInterface">Interface</a></li> 12</ul> 13</div> 14</div> 15 16<p>Android defines a user space C abstraction interface for sensor hardware. The interface header is defined in 17<code>hardware/libhardware/include/hardware/sensors.h</code>. 18In order to integrate sensors with Android you need to build a shared library that implements this interface. 19 20The types of sensors currently supported by Android include: 21<ul> 22<li>Accelerometer</li> 23<li>Magnetic Field</li> 24<li>Orientation</li> 25<li>Gyroscope</li> 26<li>Light</li> 27<li>Pressure</li> 28<li>Temperature</li> 29<li>Proximity</li> 30</ul> 31</p> 32 33<a name="androidSensorBuildingDriver"></a><h3>Building a Sensor Library</h3> 34<p> To implement a Sensors driver, create a shared library that implements the interface defined in <code>sensors.h</code>. You must name your shared library 35<code>libsensors.so</code> so that it will get loaded from <code>/system/lib</code> at runtime. 36</p> 37 38<p> The following stub file, <code>Android.mk</code>, ensures that <code>libsensors</code> compiles and links to the appropriate libraries:</p> 39 40<pre> 41LOCAL_PATH := $(call my-dir) 42include $(CLEAR_VARS) 43 44LOCAL_MODULE := sensors 45 46LOCAL_PRELINK_MODULE := false 47 48LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw 49 50LOCAL_SHARED_LIBRARIES := liblog 51# include any shared library dependencies 52 53LOCAL_SRC_FILES := sensors.c 54 55include $(BUILD_SHARED_LIBRARY) 56</pre> 57 58<a name="androidSensorsInterface"></a><h3>Interface</h3> 59 60 61<p><span class="lh3"><a name="androidDoxygenNote"></a></span> 62 63<p class="note"><strong>Note</strong>: This document relies on some Doxygen-generated content that appears in an iFrame below. To return to the Doxygen default content for this page, <a href="sensors.html">click here</a>.</p> 64 65 66<iframe onLoad="resizeDoxFrameHeight();" src="sensors_8h.html" scrolling="no" scroll="no" id="doxygen" marginwidth="0" marginheight="0" 67frameborder="0" style="width:100%;"></iframe> 68