Android_mars Learning notes _s05_001_ using Sensormanager to get sensors

Source: Internet
Author: User
<span id="Label3"></p><p><p>1.<span style="color: #008080;"> </span></p></p><p><p></p></p><pre><span style="color: #0000ff;"><span style="color: #0000ff;"></span> public</span> <span style="color: #0000ff;"><span style="color: #0000ff;">void</span></span><span style="color: #000000;"><span style="color: #000000;">onCreate (Bundle Savedinstancestate) {</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">Super</span></span><span style="color: #000000;"><span style="color: #000000;">. OnCreate (savedinstancestate); Setcontentview (r.layout.activity_main); </span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">Get Sensormanager Object</span></span>Sensormanager =<span style="color: #000000;"><span style="color: #000000;">(sensormanager) Getsystemservice (context.sensor_service); Sensorbutton</span></span>=<span style="color: #000000;"><span style="color: #000000;">(Button) Findviewbyid (r.id.sensorbutton); Sensorbutton.setonclicklistener (</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">New</span></span><span style="color: #000000;"><span style="color: #000000;">Onclicklistener () {@Override</span></span><span style="color: #0000ff;"><span style="color: #0000ff;"></span> public</span> <span style="color: #0000ff;"><span style="color: #0000ff;">void</span></span><span style="color: #000000;"><span style="color: #000000;">OnClick (View V) {</span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">by calling the Getsensorlist method, all the sensors in the current phone</span> are</span>list<sensor> sensors =<span style="color: #000000;"><span style="color: #000000;">sensormanager.getsensorlist (sensor.type_all); </span></span><span style="color: #0000ff;"><span style="color: #0000ff;"></span> for</span><span style="color: #000000;"><span style="color: #000000;">(Sensor sensor:sensors) {System.out.println (sensor.getname ()); } </span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">get the default sensor for a type by calling the Getdefaultsensor method</span></span>SENSOR sensor =<span style="color: #000000;"><span style="color: #000000;">Sensormanager.getdefaultsensor (sensor.type_light); } }); }</span></span></pre><p><p></p></p><p><p>Android_mars Learning notes _s05_001_ using Sensormanager to get sensors</p></p></span>

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.