日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

android光照传感器,详解 android 光线传感器 light sensor的使用

發布時間:2025/3/11 编程问答 72 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android光照传感器,详解 android 光线传感器 light sensor的使用 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

調用anroid的光線傳感器使用。

實現效果圖:

MainActivity.Java

package hk.ust.cse.comp107x.ligthsensor;

import android.content.Context;

import android.hardware.Sensor;

import android.hardware.SensorEvent;

import android.hardware.SensorEventListener;

import android.hardware.SensorManager;

import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;

import android.widget.TextView;

public class MainActivity extends AppCompatActivity implements SensorEventListener{

private SensorManager mSensorManager;

private Sensor mPressure;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

// Get an instance of the sensor service,and use that to get an instance of

// a particular sensor.

mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);

mPressure = mSensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);

}

@Override

public final void onAccuracyChanged(Sensor sensor,int accuracy) {

// Do something here if sensor accuracy changes.

}

@Override

public final void onSensorChanged(SensorEvent event) {

float light = event.values[0];

TextView v = (TextView)findViewById(R.id.textView);

v.setText(Float.toString(light));

// Do something with this sensor data.

}

@Override

protected void onResume() {

// Register a listener for the sensor.

super.onResume();

mSensorManager.registerListener(this,mPressure,SensorManager.SENSOR_DELAY_NORMAL);

}

@Override

protected void onPause() {

// Be sure to unregister the sensor when the activity pauses.

super.onPause();

mSensorManager.unregisterListener(this);

}

}

activity_main.xml

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:paddingBottom="@dimen/activity_vertical_margin"

android:paddingLeft="@dimen/activity_horizontal_margin"

android:paddingRight="@dimen/activity_horizontal_margin"

android:paddingTop="@dimen/activity_vertical_margin"

tools:context="hk.ust.cse.comp107x.ligthsensor.MainActivity">

android:id="@+id/textView"

android:textSize="50dp"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Hello World!"

android:layout_alignParentTop="true"

android:layout_centerHorizontal="true"

android:layout_marginTop="177dp" />

AndroidManifest.xml

package="hk.ust.cse.comp107x.ligthsensor">

android:allowBackup="true"

android:icon="@mipmap/ic_launcher"

android:label="@string/app_name"

android:supportsRtl="true"

android:theme="@style/AppTheme">

感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

總結

如果覺得編程之家網站內容還不錯,歡迎將編程之家網站推薦給程序員好友。

本圖文內容來源于網友網絡收集整理提供,作為學習參考使用,版權屬于原作者。

小編個人微信號 jb51ccc

喜歡與人分享編程技術與工作經驗,歡迎加入編程之家官方交流群!

總結

以上是生活随笔為你收集整理的android光照传感器,详解 android 光线传感器 light sensor的使用的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。