欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android編程實(shí)現(xiàn)獲取所有傳感器數(shù)據(jù)的方法

 更新時(shí)間:2017年06月01日 11:57:03   作者:jxgxy  
這篇文章主要介紹了Android編程實(shí)現(xiàn)獲取所有傳感器數(shù)據(jù)的方法,涉及Android針對傳感器Sensor相關(guān)操作技巧,需要的朋友可以參考下

本文實(shí)例講述了Android編程實(shí)現(xiàn)獲取所有傳感器數(shù)據(jù)的方法。分享給大家供大家參考,具體如下:

main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  >
<TextView
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:text="@string/hello"
  />
<TextView
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:text="加速度"
  android:id="@+id/edt1"
  />
<TextView
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:text="磁場"
  android:id="@+id/edt2"
  />
<TextView
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:text="定位"
  android:id="@+id/edt3"
  />
<TextView
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:text="陀螺儀"
  android:id="@+id/edt4"
  />
<TextView
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:text="光線"
  android:id="@+id/edt5"
  />
<TextView
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:text="壓力"
  android:id="@+id/edt6"
  />
<TextView
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:text="溫度"
  android:id="@+id/edt7"
  />
    <TextView
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:text="距離"
  android:id="@+id/edt8"
  />
<TextView
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:text="重力"
  android:id="@+id/edt9"
  />
<TextView
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:text="線性加速度"
  android:id="@+id/edt10"
  />
<TextView
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:text="旋轉(zhuǎn)矢量"
  android:id="@+id/edt11"
  />
<TextView
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:text="defalut"
  android:id="@+id/edt12"
  />
</LinearLayout>

main.java

/*
 *
 * IBMEyes.java
 * sample code for IBM Developerworks Article
 * Author: W. Frank Ableson
 * fableson@msiservices.com
 *
 */
package com.msi.ibm.eyes;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.hardware.SensorListener;
public class IBMEyes extends Activity implements SensorListener {
  final String tag = "IBMEyes";
  SensorManager sm = null;
  TextView View1 = null;
  TextView View2 = null;
  TextView View3 = null;
  TextView View4 = null;
  TextView View5 = null;
  TextView View6 = null;
  TextView View7 = null;
  TextView View8 = null;
  TextView View9 = null;
  TextView View10 = null;
  TextView View11 = null;
  TextView View12 = null;
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    sm = (SensorManager) getSystemService(SENSOR_SERVICE);
    setContentView(R.layout.main);
    View1 = (TextView) findViewById(R.id.edt1);
    View2 = (TextView) findViewById(R.id.edt2);
    View3 = (TextView) findViewById(R.id.edt3);
    View4 = (TextView) findViewById(R.id.edt4);
    View5 = (TextView) findViewById(R.id.edt5);
    View6 = (TextView) findViewById(R.id.edt6);
    View7 = (TextView) findViewById(R.id.edt7);
    View8 = (TextView) findViewById(R.id.edt8);
    View9 = (TextView) findViewById(R.id.edt9);
    View10 = (TextView) findViewById(R.id.edt10);
    View11 = (TextView) findViewById(R.id.edt11);
    View12 = (TextView) findViewById(R.id.edt12);
  }
  public void onSensorChanged(int sensor, float[] values) {
    synchronized (this) {
      String str = "X:" + values[0] + ",Y:" + values[1] + ",Z:" + values[2];
      switch (sensor){
      case Sensor.TYPE_ACCELEROMETER:
        View1.setText("加速度:" + str);
        break;
      case Sensor.TYPE_MAGNETIC_FIELD:
        View2.setText("磁場:" + str);
        break;
      case Sensor.TYPE_ORIENTATION:
        View3.setText("定位:" + str);
        break;
      case Sensor.TYPE_GYROSCOPE:
        View4.setText("陀螺儀:" + str);
        break;
      case Sensor.TYPE_LIGHT:
        View5.setText("光線:" + str);
        break;
      case Sensor.TYPE_PRESSURE:
        View6.setText("壓力:" + str);
        break;
      case Sensor.TYPE_TEMPERATURE:
        View7.setText("溫度:" + str);
        break;
      case Sensor.TYPE_PROXIMITY:
        View8.setText("距離:" + str);
        break;
      case Sensor.TYPE_GRAVITY:
        View9.setText("重力:" + str);
        break;
      case Sensor.TYPE_LINEAR_ACCELERATION:
        View10.setText("線性加速度:" + str);
        break;
      case Sensor.TYPE_ROTATION_VECTOR:
        View11.setText("旋轉(zhuǎn)矢量:" + str);
        break;
      default:
        View12.setText("NORMAL:" + str);
        break;
      }
    }
  }
  public void onAccuracyChanged(int sensor, int accuracy) {
    Log.d(tag,"onAccuracyChanged: " + sensor + ", accuracy: " + accuracy);
  }
  @Override
  protected void onResume() {
    super.onResume();
    sm.registerListener(this,
        Sensor.TYPE_ACCELEROMETER |
        Sensor.TYPE_MAGNETIC_FIELD |
        Sensor.TYPE_ORIENTATION |
        Sensor.TYPE_GYROSCOPE |
        Sensor.TYPE_LIGHT |
        Sensor.TYPE_PRESSURE |
        Sensor.TYPE_TEMPERATURE |
        Sensor.TYPE_PROXIMITY |
        Sensor.TYPE_GRAVITY |
        Sensor.TYPE_LINEAR_ACCELERATION |
        Sensor.TYPE_ROTATION_VECTOR,
        SensorManager.SENSOR_DELAY_NORMAL);
  }
  @Override
  protected void onStop() {
    sm.unregisterListener(this);
    super.onStop();
  }
}

更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android基本組件用法總結(jié)》、《Android視圖View技巧總結(jié)》、《Android布局layout技巧總結(jié)》、《Android資源操作技巧匯總》、《Android文件操作技巧匯總》、《Android開發(fā)入門與進(jìn)階教程》、《Android編程之a(chǎn)ctivity操作技巧總結(jié)》及《Android控件用法總結(jié)

希望本文所述對大家Android程序設(shè)計(jì)有所幫助。

相關(guān)文章

  • android 關(guān)于利用簽名的SHA1進(jìn)行安全校驗(yàn)的方法之一(推薦)

    android 關(guān)于利用簽名的SHA1進(jìn)行安全校驗(yàn)的方法之一(推薦)

    下面小編就為大家?guī)硪黄猘ndroid 關(guān)于利用簽名的SHA1進(jìn)行安全校驗(yàn)的方法之一(推薦)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-01-01
  • Flutter?Ping檢查服務(wù)器通訊信號強(qiáng)度實(shí)現(xiàn)步驟

    Flutter?Ping檢查服務(wù)器通訊信號強(qiáng)度實(shí)現(xiàn)步驟

    這篇文章主要為大家介紹了Flutter?Ping檢查服務(wù)器通訊信號強(qiáng)度實(shí)現(xiàn)步驟詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-06-06
  • Android如何給Textview添加菜單項(xiàng)詳解(Java)

    Android如何給Textview添加菜單項(xiàng)詳解(Java)

    TextView是android里面用的最多的控件,TextView類似一般UI中的Label,TextBlock等控件,只是為了單純的顯示一行或多行文本,下面這篇文章主要給大家介紹了關(guān)于Android如何給Textview添加菜單項(xiàng)的相關(guān)資料,需要的朋友可以參考下
    2022-01-01
  • Android 多線程實(shí)現(xiàn)重復(fù)啟動(dòng)與停止的服務(wù)

    Android 多線程實(shí)現(xiàn)重復(fù)啟動(dòng)與停止的服務(wù)

    這篇文章主要介紹了Android 多線程實(shí)現(xiàn)重復(fù)啟動(dòng)與停止的服務(wù)的相關(guān)資料,多線程環(huán)境下為了避免死鎖,一般提倡開放調(diào)用,開放調(diào)用可以避免死鎖,它的代價(jià)是失去原子性,這里說明重復(fù)啟動(dòng)與停止的服務(wù),需要的朋友可以參考下
    2017-08-08
  • Android AS為xutils添加依賴過程圖解

    Android AS為xutils添加依賴過程圖解

    這篇文章主要介紹了Android AS為xutils添加依賴過程圖解,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-11-11
  • ReactiveCocoa代碼實(shí)踐之-更多思考

    ReactiveCocoa代碼實(shí)踐之-更多思考

    這篇文章主要介紹了ReactiveCocoa代碼實(shí)踐之-更多思考的相關(guān)資料,需要的朋友可以參考下
    2016-04-04
  • Android開發(fā)者必備的十個(gè)工具介紹

    Android開發(fā)者必備的十個(gè)工具介紹

    這篇文章主要介紹了Android開發(fā)者必備的十個(gè)工具介紹,在這篇文章中,討論了10個(gè)最常見的工具,android 開發(fā)者應(yīng)該了解和學(xué)習(xí)使用,需要的朋友可以參考下
    2015-03-03
  • Android實(shí)現(xiàn)跑馬燈效果的方法

    Android實(shí)現(xiàn)跑馬燈效果的方法

    這篇文章主要介紹了Android實(shí)現(xiàn)跑馬燈效果的方法,通過頁面XML布局設(shè)置實(shí)現(xiàn)帶有跑馬燈效果的文字滾動(dòng)顯示功能,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-10-10
  • Android開發(fā)教程之如何屏蔽View的重復(fù)點(diǎn)擊

    Android開發(fā)教程之如何屏蔽View的重復(fù)點(diǎn)擊

    這篇文章主要給大家介紹了關(guān)于Android開發(fā)教程之如何屏蔽View的重復(fù)點(diǎn)擊的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2018-09-09
  • android實(shí)現(xiàn)圓角矩形背景的方法

    android實(shí)現(xiàn)圓角矩形背景的方法

    這篇文章主要介紹了android實(shí)現(xiàn)圓角矩形背景的方法,以實(shí)例形式分析了Android編程實(shí)現(xiàn)圓角矩形背景的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-10-10

最新評論