{"id":2008,"date":"2013-07-05T11:29:39","date_gmt":"2013-07-05T11:29:39","guid":{"rendered":"http:\/\/truelogic.org\/wordpress\/?p=2008"},"modified":"2013-07-05T12:57:25","modified_gmt":"2013-07-05T12:57:25","slug":"list-of-sensors-in-an-android-phone","status":"publish","type":"post","link":"https:\/\/truelogic.org\/wordpress\/2013\/07\/05\/list-of-sensors-in-an-android-phone\/","title":{"rendered":"List of Sensors in an Android Phone"},"content":{"rendered":"            <script type=\"text\/javascript\" src=\"https:\/\/truelogic.org\/wordpress\/wp-content\/plugins\/wordpress-code-snippet\/scripts\/shBrushJava.js\"><\/script>\n            <script type=\"text\/javascript\" src=\"https:\/\/truelogic.org\/wordpress\/wp-content\/plugins\/wordpress-code-snippet\/scripts\/shBrushXml.js\"><\/script>\n<p>A small utility to display the list of Sensors present in an Android phone.<br \/>\nFor those who are not interested in the code, the installable apk file is provided as a downloadable link at the end of this article.<\/p>\n<h2>The Activity class<\/h2>\n<p><pre class=\"brush: java\">package com.example.listsensors;\r\n\r\nimport java.util.List;\r\n\r\nimport android.os.Bundle;\r\nimport android.hardware.Sensor;\r\nimport android.hardware.SensorManager;\r\nimport android.app.Activity;\r\nimport android.content.Context;\r\nimport android.view.Menu;\r\nimport android.widget.TextView;\r\n\r\npublic class MainActivity extends Activity {\r\n\r\n\t@Override\r\n\tprotected void onCreate(Bundle savedInstanceState) {\r\n\t\tsuper.onCreate(savedInstanceState);\r\n\t\tsetContentView(R.layout.activity_main);\r\n\t\t\r\n\t\tSensorManager mgr = (SensorManager) getSystemService(Context.SENSOR_SERVICE);\r\n\t\tList sensors = mgr.getSensorList(Sensor.TYPE_ALL);\r\n\t\t\r\n\t\tString data = &quot;&quot;;\r\n\t\tfor(int i =0; i &lt; sensors.size(); i++) {\r\n\t\t\t\tSensor s = (Sensor) sensors.get(i);\r\n\t\t\t\tdata += s.getName() + &quot;\\r\\n&quot;;\r\n\t\t}\r\n\t\tTextView view = (TextView) findViewById(R.id.txtList);\r\n\t\tview.setText(data);\r\n\t}\r\n\r\n\t@Override\r\n\tpublic boolean onCreateOptionsMenu(Menu menu) {\r\n\t\t\/\/ Inflate the menu; this adds items to the action bar if it is present.\r\n\t\tgetMenuInflater().inflate(R.menu.main, menu);\r\n\t\treturn true;\r\n\t}\r\n\r\n}\r\n<\/pre><\/p>\n<h2>The Layout xml<\/h2>\n<p><pre class=\"brush: xml\">&lt;RelativeLayout xmlns:android=&quot;http:\/\/schemas.android.com\/apk\/res\/android&quot;\r\n    xmlns:tools=&quot;http:\/\/schemas.android.com\/tools&quot;\r\n    android:layout_width=&quot;match_parent&quot;\r\n    android:layout_height=&quot;match_parent&quot;\r\n    android:paddingBottom=&quot;@dimen\/activity_vertical_margin&quot;\r\n    android:paddingLeft=&quot;@dimen\/activity_horizontal_margin&quot;\r\n    android:paddingRight=&quot;@dimen\/activity_horizontal_margin&quot;\r\n    android:paddingTop=&quot;@dimen\/activity_vertical_margin&quot;\r\n    tools:context=&quot;.MainActivity&quot; &gt;\r\n\r\n    &lt;TextView\r\n        android:id=&quot;@+id\/txtList&quot;\r\n        android:layout_width=&quot;wrap_content&quot;\r\n        android:layout_height=&quot;wrap_content&quot;\r\n        android:text=&quot;@string\/hello_world&quot; \/&gt;\r\n\r\n&lt;\/RelativeLayout&gt;<\/pre><\/p>\n<p>The installable APK file<a title=\"ListSensors\" href=\"http:\/\/truelogic.org\/ListSensors.apk\"> can be downloaded from here.<\/a><\/p>\n<p><strong>Be sure to allow Unknown Sources in your Settings-&gt;Applications, since this app is not part of the Google Play Store.<\/strong><\/p>\n<p>Here is a screenshot of how it looks.\u00a0 (Sorry not very clear).<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-large wp-image-1968\" alt=\"normal\" src=\"https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2013\/07\/IMG00067-20130705-1804-150x150.jpg\" width=\"150\" height=\"150\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>A small utility to display the list of Sensors present in an Android phone. For those who are not interested in the code, the installable <a class=\"mh-excerpt-more\" href=\"https:\/\/truelogic.org\/wordpress\/2013\/07\/05\/list-of-sensors-in-an-android-phone\/\" title=\"List of Sensors in an Android Phone\">[&#8230;]<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":2014,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[295],"tags":[],"class_list":["post-2008","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-android-dev"],"_links":{"self":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/2008","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/comments?post=2008"}],"version-history":[{"count":11,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/2008\/revisions"}],"predecessor-version":[{"id":2017,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/2008\/revisions\/2017"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/media\/2014"}],"wp:attachment":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/media?parent=2008"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/categories?post=2008"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/tags?post=2008"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}