Home >> Miscellaneous
Mobile devices with Android Platform might have some hardware sensors
built-in and ready to make use of those with the help of Android API.
Recently I bought a mobile phone with Android Platform installed in it,
and I wanted to know what all hardware sensors are present in it, and
in working condition. So I thought of writing a simple Application using
Android Platform/API and list down all the functional hardware sensors
present and running in my mobile phone.
As a result, following is the program source code, that can show/list out
all those Hardware sensors on screen, of course after this application
is compiled and ported and installed in the actual device.
TestSensor.java
package example.demo;
import java.util.Iterator;
import java.util.List;
import android.app.Activity;
import android.graphics.Color;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
public class TestSensor extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SensorManager sm = (SensorManager) getApplicationContext().
getSystemService(SENSOR_SERVICE);
LinearLayout linearLayout = new LinearLayout(getApplicationContext());
List list = sm.getSensorList(Sensor.TYPE_ALL);
Iterator itr = list.iterator();
TextView txtView = null;
TableLayout tableLayout = new TableLayout(this);
ViewGroup.LayoutParams params =
new ViewGroup.LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT);
tableLayout.setLayoutParams(params);
TableRow tableRow = null;
while(itr.hasNext()) {
txtView = new TextView(getApplicationContext());
txtView.setTextColor(Color.BLACK);
tableRow = new TableRow(this);
tableRow.setBackgroundColor(Color.YELLOW);
Sensor sensor = (Sensor)itr.next();
txtView.setText(sensor.getName());
tableRow.addView(txtView);
tableLayout.addView(tableRow);
}
linearLayout.addView(tableLayout);
setContentView(linearLayout);
}
}
|
This application is being first tested on Android Emulator and then I have
executed it in my personal mobile phone to see the result on a real device.
(Disclaimer: use of this program at you own risk)
If anything missed out , please let me know at
techienjoy at yahoo . com
| Android ListView Example : |
Example on Android ListView and
explained with a very simple scenario
and article with appropriate screens
captured and shown.
|
|
|
| Android Tab View Example : |
Example on Android Tab View
explained with a very simple scenario
and appropriate screens captured and shown.
|
|
|
|
|
|
|
|
| Android Sensors Example : |
Example on Android Sensors Listed and
explained with a very simple scenario
and article with appropriate screens
captured and shown.
|
|
|
|
| Android Examples : |
List of ANDROid examples
with source code and output
screens captured and shown.
|
|
|
|
|
| Google GWT Example : |
Example using GWT and some design patterns and various
ways of implementing this example.
|
|
|
| Android Gallery Example : |
Example on Android Gallery View
explained with a very simple scenario
and appropriate screens captured and shown.
|
|
| Android ListView Example : |
Example on Android ListView
explained with a very simple scenario
whereby showing folder and files with
structure and appropriate screens
captured and shown.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| Android ListView Example : |
Example on Android List View
explained with a very simple scenario
and article with appropriate screens
captured and shown.
|
|
|
|
|