當前位置:首頁 » 安卓系統 » android感測器開發

android感測器開發

發布時間: 2022-06-30 09:02:52

㈠ 開發android應用程序怎麼調用光感測器

Android手機自帶光線感測器,通常我們手機的屏幕自動亮度都是用光線感測器來實現的。該感測器在前置攝像頭附近,此外,還有一個距離感測器。本文主要講解如何使用Android手機的光線感測器。

獲得感應器服務

Android開發中要使用光線感測器,需要先獲得系統感測器服務Context.SENSOR_SERVICE,獲得方法如下:

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

獲得光線感測器

SensorManager是系統感測器服務,是系統所有感測器的管理器。通過它,我們獲得制定類型的感測器,獲得光線感測器的方法如下:

詳細代碼

㈡ Android如何獲取手機指紋感測器檢測到的信息

回答
Android如何獲取手機指紋感測器檢測到的信息?
我想做一個APP,它能夠提示用戶觸摸指紋感測器,APP獲取指紋感測器檢測到的信息,這個信息要具有唯一性(因為指紋是唯一的),然後APP把這個信息發送到伺服器。那麼,各位大神,能否提示一下,這個信息如何獲取到?我使用AndroidStudio進行開發的。
展開
手機 Android開發 攜帶型設備 電子產品 Android

㈢ Android 感測器的 數據流和框架 是怎麼樣讓 屏幕旋轉

這篇文章寫的感測器數據從驅動傳遞到應用程序的整個流程,還有數據校正的問題。

應用程序怎麼樣設置可以讓自己隨著設備的傾斜度變化而旋轉方向呢?在AndroidManifest.xml文件中的android:screenOrientation就可以了。這里追蹤一下它的內部機制。
先看一個最關鍵的部件:/frameworks/base/core/java/android/view/WindowOrientationListener.java
這個介面注冊一個accelerator,並負責把accelerator的數據轉化為orientation。這個API對應用程序不公開,我看Android2.3的源碼時發現只有PhoneWindowManager使用到它了。
/frameworks/base/policy/../PhoneWindowManager.java
PhonwWindowManager注冊了一個WindowOrientationListener,就可以非同步獲取當前設備的orientation了。再結合應用程序在AndroidManifest.xml中設置的值來管理著應用程序界面的旋轉方向。以下是PhoneWindowManager.java中相關的兩個代碼片段。

[java] view plain
public void onOrientationChanged(int rotation) {
// Send updates based on orientation value
if (localLOGV) Log.v(TAG, "onOrientationChanged, rotation changed to " +rotation);
try {
mWindowManager.setRotation(rotation, false,
mFancyRotationAnimation);
} catch (RemoteException e) {
// Ignore

}
}
... ...
switch (orientation) {//這個值就是當前設備屏幕的旋轉方向,再結合應用程序設置的android:configChanges屬性值就可以確定應用程序界面的旋轉方向了。應用程序設置值的優先順序大於感測器確定的優先順序。
case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
//always return portrait if orientation set to portrait
return mPortraitRotation;
case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
//always return landscape if orientation set to landscape
return mLandscapeRotation;
case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
//always return portrait if orientation set to portrait
return mUpsideDownRotation;
case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
//always return seascape if orientation set to reverse landscape
return mSeascapeRotation;
case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
//return either landscape rotation based on the sensor
mOrientationListener.setAllow180Rotation(
isLandscapeOrSeascape(Surface.ROTATION_180));
return getCurrentLandscapeRotation(lastRotation);
case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
mOrientationListener.setAllow180Rotation(
!isLandscapeOrSeascape(Surface.ROTATION_180));
return getCurrentPortraitRotation(lastRotation);
}

讓應用程序隨屏幕方向自動旋轉的實現原理就這么交待完了。我解決這一步時也沒有費多少力氣,在板子上打開SensorTest,對比一下XYZ三個軸和MileStone上面的數據,修改一下正負值就可以了。但要解決Teeter運行時Z軸反轉的問題,還得深層次挖一挖。

PhoneWindowManager.java中有這么一句:
mWindowManager.setRotation(rotation, false, mFancyRotationAnimation);
當PhonewindowManager通過WindowOrientationListener這個監聽器得知屏幕方向改變時,會通知給WindowManagerService(/frameworks/base/service/../WindowManagerService.java)
WindowManagerService中有這么一個監聽器集合:mRotationWatchers,誰想監聽屏幕方向改變,就會在這里注冊一個監聽器。SensorManager就這么幹了。然後,通過下面這個非同步方法獲知當前的屏幕方向

㈣ android應用開發中的感測器SensorManager mSensorManager 抽象類定義疑惑

只是轉換類型,例子中,getSystemService(SENSOR_SERVICE)得到的對象已經實例化。

熱點內容
大學php開發培訓 發布:2024-04-20 08:04:35 瀏覽:987
小米2s存儲設置 發布:2024-04-20 07:58:38 瀏覽:900
株洲移動網路伺服器地址 發布:2024-04-20 07:45:48 瀏覽:689
119濃度的鹽酸怎麼配置 發布:2024-04-20 06:23:38 瀏覽:119
資料庫pf 發布:2024-04-20 05:57:36 瀏覽:393
c語言編譯出現連接錯誤 發布:2024-04-20 05:42:18 瀏覽:198
湖北戴爾伺服器維修系統雲主機 發布:2024-04-20 05:36:47 瀏覽:62
android上傳數據 發布:2024-04-20 05:36:43 瀏覽:143
python替換文本內容 發布:2024-04-20 05:21:22 瀏覽:899
urllib3源碼 發布:2024-04-20 05:11:23 瀏覽:35