android 获取手机中所有的传感器Sensor类使用方法
2012-09-03 16:21
706 查看
高仿QQ设置滑动按钮,漂亮简单
http://www.eoeandroid.com/thread-196576-1-1.html
原创:实战db4o数据库01
http://www.eoeandroid.com/thread-196073-1-1.html
Android应用调用浏览器和电话的URI
http://www.eoeandroid.com/thread-195752-1-1.html
代码很简单,自己看就能明白,只是为了练习一下Sensor类的使用方法。算是一个练习.
本文出自 “Android小子的” 博客,请务必保留此出处http://androidrigl.blog.51cto.com/7531835/1247557
http://www.eoeandroid.com/thread-196576-1-1.html
原创:实战db4o数据库01
http://www.eoeandroid.com/thread-196073-1-1.html
Android应用调用浏览器和电话的URI
http://www.eoeandroid.com/thread-195752-1-1.html
代码很简单,自己看就能明白,只是为了练习一下Sensor类的使用方法。算是一个练习.
package mars.com; import java.util.List; import android.app.Activity; import android.content.Context; import android.hardware.Sensor; import android.hardware.SensorManager; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.TextView; public class DemoSensorActivity extends Activity { private Button button; private TextView show; private SensorManager sm; private StringBuffer str; private List<Sensor> allSensors; private Sensor s; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); button = (Button) findViewById(R.id.button); show = (TextView) findViewById(R.id.show); button.setOnClickListener(new ButtonListener()); sm = (SensorManager) getSystemService(Context.SENSOR_SERVICE); allSensors = sm.getSensorList(Sensor.TYPE_ALL);// 获得传感器列表 } class ButtonListener implements OnClickListener { public void onClick(View v) { str = new StringBuffer(); str.append("该手机有" + allSensors.size() + "个传感器,分别是:\n"); for (int i = 0; i < allSensors.size(); i++) { s = allSensors.get(i); str.append("设备名称:" + s.getName() + "\n"); str.append("设备版本:" + s.getVersion() + "\n"); str.append("通用类型号:" + s.getType() + "\n"); str.append("设备商名称:" + s.getVendor() + "\n"); str.append("传感器功耗:" + s.getPower() + "\n"); str.append("传感器分辨率:" + s.getResolution() + "\n"); str.append("传感器最大量程:" + s.getMaximumRange() + "\n"); switch (s.getType()) { case Sensor.TYPE_ACCELEROMETER: str.append(i + "加速度传感器"); break; case Sensor.TYPE_GYROSCOPE: str.append(i + "陀螺仪传感器"); break; case Sensor.TYPE_LIGHT: str.append(i + "环境光线传感器"); break; case Sensor.TYPE_MAGNETIC_FIELD: str.append(i + "电磁场传感器"); break; case Sensor.TYPE_ORIENTATION: str.append(i + "方向传感器"); break; case Sensor.TYPE_PRESSURE: str.append(i + "压力传感器"); break; case Sensor.TYPE_PROXIMITY: str.append(i + "距离传感器"); break; case Sensor.TYPE_TEMPERATURE: str.append(i + "温度传感器"); break; default: str.append(i + "未知传感器"); break; } } show.setText(str); } } }布局文件
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <Button android:id="@+id/button" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="获取传感器" /> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" > <TextView android:id="@+id/show" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </ScrollView> </LinearLayout>
本文出自 “Android小子的” 博客,请务必保留此出处http://androidrigl.blog.51cto.com/7531835/1247557
相关文章推荐
- android 获取手机中所有的传感器Sensor类使用方法
- android 获取手机中所有的传感器Sensor类使用方法
- Android Loader的使用以及手机通讯录的获取方法
- Android之如何获取手机中所有的传感器
- android 获取手机中的所有图片或某一目录下的图片方法
- Android ListView的使用优化以及获取手机所有应用程序
- Android(java)学习笔记109:通过反射获取成员变量和成员方法并且使用
- Android编程实现全局获取Context及使用Intent传递对象的方法详解
- 使用反射获取一个类的所有方法和字段
- Android逆向之旅---获取加固后应用App的所有方法信息
- 在Android中使用加载器(Loader)来实现获取本机中的所有图片,并进行查看图片的效果
- Android逆向之旅---获取加固后应用App的所有方法信息
- VisionMobile:2015年Android使用的全球趋势(七)印度用户从手机中获取最多
- PHP使用strstr()函数获取指定字符串后所有字符的方法
- Android 使用ContentResolver获取手机图片和照片的相关信息
- 使用DOM的方法获取所有li元素,然后使用jQuery()构造函数把它封装为jQuery对象
- Android高手进阶教程(十一)之----Android 通用获取Ip的方法(判断手机是否联网的方法)!
- Android逆向之旅---获取加固后应用App的所有方法信息
- PHP使用strstr()函数获取指定字符串后所有字符的方法
- Android中列出手机的所有应用和剩余内存使用情况