国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

安卓開發(fā)實例:方向傳感器

這篇具有很好參考價值的文章主要介紹了安卓開發(fā)實例:方向傳感器。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

調用手機的方向傳感器,X軸,Y軸,Z軸的數值
安卓開發(fā)實例:方向傳感器,android

activity_sensor.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  tools:context="com.weijun901.randomNum.Second">

  <LinearLayout
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center" tools:ignore="MissingConstraints">
    <LinearLayout
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:background="#F8BBD0"
      android:gravity="center">
      <TextView
        android:text="傾斜角(X軸):"
        android:textSize="30sp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:id="@+id/tvX" tools:ignore="HardcodedText"/>
      <TextView
        android:text="TextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:id="@+id/tv1" android:layout_weight="1"
        tools:ignore="HardcodedText,InefficientWeight"/>
    </LinearLayout>
    <LinearLayout
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:background="#B2DFDB">
      <TextView
        android:text="滾動角(Y軸):"
        android:textSize="30dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:id="@+id/tvY" tools:ignore="HardcodedText,SpUsage"/>
      <TextView
        android:text="TextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:id="@+id/tv2" android:layout_weight="1"
        tools:ignore="HardcodedText,InefficientWeight"/>
    </LinearLayout>
    <LinearLayout
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:background="#B3E5FC">
      <TextView
        android:text="方位角(Z軸):"
        android:textSize="30dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:id="@+id/tvZ" tools:ignore="HardcodedText,SpUsage"/>
      <TextView
        android:text="TextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:id="@+id/tv3" android:layout_weight="1"
        tools:ignore="HardcodedText,InefficientWeight"/>
    </LinearLayout>
    <Button
      android:text="Main"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:onClick="toMainActivity"
      android:id="@+id/button" tools:ignore="HardcodedText"/>
  </LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

Sensor.java文章來源地址http://www.zghlxwxcb.cn/news/detail-735261.html

package com.weijun901.show;

import android.content.Intent;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.view.View;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;

public class Sensor extends AppCompatActivity implements SensorEventListener {
  private TextView tv1;
  private TextView tv2;
  private TextView tv3;
  private SensorManager sManager;
  private android.hardware.Sensor mSensorOrientation;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_sensor);

    // 設置標題欄的文字
    getSupportActionBar().setTitle("方向傳感器");

    sManager = (SensorManager) getSystemService(SENSOR_SERVICE);
    mSensorOrientation = sManager.getDefaultSensor(android.hardware.Sensor.TYPE_ORIENTATION);
    sManager.registerListener(this, mSensorOrientation, SensorManager.SENSOR_DELAY_UI);
    bindViews();
  }
  private void bindViews() {
    tv1 = findViewById(R.id.tv1);
    tv2 = findViewById(R.id.tv2);
    tv3 = findViewById(R.id.tv3);
  }
  @Override
  public void onSensorChanged(SensorEvent event) {
    tv1.setText((float) (Math.round(event.values[1] * 100)) / 100 + "°");
    tv2.setText((float) (Math.round(event.values[2] * 100)) / 100 + "°");
    tv3.setText((float) (Math.round(event.values[0] * 100)) / 100 + "°");
  }

  public void toMainActivity(View view) {
    Intent intent = new Intent(this, MainActivity.class); // 替換為目標頁面的類名
    startActivity(intent);
  }

  @Override
  public void onAccuracyChanged(android.hardware.Sensor sensor, int accuracy) {

  }

  @Override
  protected void onDestroy() {
    super.onDestroy();
    sManager.unregisterListener(this);
  }
}

到了這里,關于安卓開發(fā)實例:方向傳感器的文章就介紹完了。如果您還想了解更多內容,請在右上角搜索TOY模板網以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網!

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。如若轉載,請注明出處: 如若內容造成侵權/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經查實,立即刪除!

領支付寶紅包贊助服務器費用

相關文章

  • STM32開發(fā)(15)----芯片內部溫度傳感器

    STM32開發(fā)(15)----芯片內部溫度傳感器

    本章介紹STM32芯片溫度傳感器的使用方法和獲取方法。 STM32 有一個內部的溫度傳感器,可以用來測量 CPU 及周圍的溫度( 內部溫度傳感器更適合于檢測溫度的變化,需要測量精確溫度的情況下,應使用外置傳感器 )。對于 STM32F103來說,該溫度傳感器在內部和 ADC1_IN16 輸入通道相

    2024年02月05日
    瀏覽(23)
  • Arduino開發(fā)之如何連接壓力傳感器模塊?

    Arduino開發(fā)之如何連接壓力傳感器模塊?

    ??在利用Arduino開發(fā)過程中,若需知道設備能感知到受到外部按壓,設備可以通過壓力傳感器模塊來感知周圍環(huán)境。本文在【Arduino如何進行開發(fā)?】基礎上,借鑒現有網絡資料,闡述Arduino如何連接壓力傳感器模塊。 ?? ??壓力傳感器模塊為電阻式薄膜壓力傳感器模塊。

    2023年04月15日
    瀏覽(39)
  • 【Android開發(fā)基礎】手機傳感器信息的獲取

    【Android開發(fā)基礎】手機傳感器信息的獲取

    描述:關于傳感器的使用,我在同欄目下發(fā)了一篇關于傳感器(方向傳感器、加速度傳感器)的使用,這篇博客主要以獲取不同手機所支持的傳感器信息為主,具體如何使用這些傳感器,需要自己進行查閱和學習,也可以私聊我。 博客:傳感器(方向傳感器、加速度傳感器)

    2024年02月10日
    瀏覽(33)
  • ESP32-C3 應用 篇(實例二、通過藍牙將傳感器數據發(fā)送給手機,手機端控制 SK6812 LED)

    ESP32-C3 應用 篇(實例二、通過藍牙將傳感器數據發(fā)送給手機,手機端控制 SK6812 LED)

    前面文章說過,藍牙協議博主了解不是很深入,只進行一些基礎的了解,示例的測試,和初學者一樣,基本上藍牙專欄系列博文都是一步一步摸索過來的,功夫不負有心人,到目前為止,多多少少對藍牙 GATT 有了一定的認識。 那么我們今天就要學以致用,使用 ESP32-C3 的藍牙

    2024年02月09日
    瀏覽(17)
  • ESP32 Arduino開發(fā) DHT11傳感器

    ESP32 Arduino開發(fā) DHT11傳感器

    參考:CSDN博客 打開庫管理工具 工具 - 管理庫... 查找所需要的程序庫 安裝 DHT sensor library DHT對象創(chuàng)建的函數需要兩個參數,一個是用于獲取數據的引腳號,一個是傳感器的類型(可選DHT11、DHT21、DHT22)。 所以在創(chuàng)建對象之前,通過宏定義的方式對于所需要的兩個參數進行定義

    2024年02月03日
    瀏覽(43)
  • 3個月快速入門LoRa物聯網傳感器開發(fā)

    3個月快速入門LoRa物聯網傳感器開發(fā)

    在這里插入圖片描述 LoRa作為一種LPWAN(低功耗廣域網絡)無線通信技術,非常適合物聯網傳感器和行業(yè)應用。要快速掌握LoRa開發(fā),需要系統學習理論知識,并通過實際項目積累經驗。 摘要: 先學習LoRa基礎知識:原理、網絡架構、協議等,大概需要2周時間。 然后選擇LoRa開發(fā)板,編寫簡

    2024年02月14日
    瀏覽(25)
  • STM32外設芯片驅動學習記錄 —— (一) BH1750光照傳感器驅動開發(fā)

    STM32外設芯片驅動學習記錄 —— (一) BH1750光照傳感器驅動開發(fā)

    一、芯片介紹 二、Datasheet解讀 1.硬件說明 2.寄存器說明 3.通信過程 三、驅動代碼編寫 1.軟件I2C驅動 2. BH1750芯片驅動函數 總結 ? ? ? ? ? ? BH1750是16位數字輸出型,環(huán)境光強度傳感器集成電路,使用I2C接口通信,工作電壓:VCC(2.4~3.6V),I2C電平(1.65~VCC),用于各類消費類LCD屏

    2024年02月02日
    瀏覽(17)
  • Clion開發(fā)Stm32之溫濕度傳感器(DHT11)驅動編寫

    涵蓋之前文章: Clion開發(fā)STM32之HAL庫GPIO宏定義封裝(最新版) Clion開發(fā)stm32之微妙延遲(采用nop指令實現) Clion開發(fā)STM32之日志模塊(參考RT-Thread) 頭文件 源文件

    2024年02月15日
    瀏覽(26)
  • 使用 Qt for Android 獲取并利用手機傳感器數據(上篇)開發(fā)環(huán)境省心搭建

    使用 Qt for Android 獲取并利用手機傳感器數據(上篇)開發(fā)環(huán)境省心搭建

    現代手機擁有許多傳感器,包括地磁、姿態(tài)、GPS、光照、溫度、氣壓、攝像、聲音、電磁等,完全就是一個高度集成的科學儀器。不夸張的說,一部手機加上一個外圍的計算機和控制系統,做一個功能較強的自主移動機器人并不是不可能。但是,很多APP都只是局限于自身的功

    2024年02月03日
    瀏覽(35)
  • 為減少來自環(huán)境使用的無線傳感器網絡的傳輸次數而開發(fā)的方法(Matlab代碼實現)

    為減少來自環(huán)境使用的無線傳感器網絡的傳輸次數而開發(fā)的方法(Matlab代碼實現)

    ???????? 歡迎來到本博客 ???????? ??博主優(yōu)勢: ?????? 博客內容盡量做到思維縝密,邏輯清晰,為了方便讀者。 ?? 座右銘: 行百里者,半于九十。 ?????? 本文目錄如下: ?????? 目錄 ??1 概述 ??2 運行結果 ??3 參考文獻 ??4 Matlab代碼實現 隨著無線

    2024年02月08日
    瀏覽(25)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領取紅包,優(yōu)惠每天領

二維碼1

領取紅包

二維碼2

領紅包