androidTV相關開發指導1

谷歌電視相關開發api

#### google tv 1 設置tv App

1.升級開發工具到最新版本

2.manifest設置

 2.1 android:theme="@style/Theme.Leanback"

 2.2 <category android:name="android.intent.category.LEANBACK_LAUNCHER" />

<activity

    android:name="com.example.android.TvActivity"

    android:label="@string/app_name"

    android:theme="@style/Theme.Leanback">

    <intent-filter>

      <action android:name="android.intent.action.MAIN" />

      <category android:name="android.intent.category.LEANBACK_LAUNCHER" />

    </intent-filter>

  </activity>

 

3 觸屏支持 不支持觸屏操作

<uses-feature android:name="android.hardware.touchscreen"

              android:required="false" />

  

  

4. 提供一個橫幅用於所有的activity,或者針對每一個activity設置屬性

<application

    ...

    android:banner="@drawable/banner" >

    ...

</application>

5.添加Android TV 支持庫 目錄 <sdk>/extras/android/support/

5.1 v17 leanback library  提供tv用戶界面部件,特別用於媒體應用

5.2 v7 recycleview library 高效管理長列表內容內存,leanback需要

5.3 v7  cardview library 顯示信息卡片 特別是媒體圖片和描述

但是,以上支持庫不是必須使用的,但是推薦在媒體分類的瀏覽的應用中使用。

如果你使用了leanback 包,就不用使用 v4包,v7reycle包河v17 leanbackback

包。

v17包包含一些資源文件,必須把那些資源文件導入到你的app。

和v7包的加入方式一樣:https://developer.android.com/tools/support-library/setup.html#libs-with-res

6 硬件相關檢測 api13

UiModeManager uiModeManager = (UiModeManager) getSystemService(UI_MODE_SERVICE);

if (uiModeManager.getCurrentModeType()==Configuration.UI_MODE_TYPE_TELEVISION) {

 // tv 模式

}else if (uiModeManager.getCurrentModeType()==Configuration.UI_MODE_TYPE_CAR) {

//汽車

}

7.在tv上,不支持的硬件特性

觸屏操作 , 撥打電話,視頻,近場通信,gps定位,麥克風支持

Hardware Android feature descriptor

--------------------------------------------------------------------------------

Touchscreen android.hardware.touchscreen

Telephony android.hardware.telephony

Camera android.hardware.camera

Near Field Communications (NFC) android.hardware.nfc

GPS android.hardware.location.gps

Microphone android.hardware.microphone

設置:

<uses-feature android:name="android.hardware.touchscreen"

        android:required="false"/>

<uses-feature android:name="android.hardware.telephony"

        android:required="false"/>

<uses-feature android:name="android.hardware.camera"

        android:required="false"/>

<uses-feature android:name="android.hardware.nfc"

        android:required="false"/>

<uses-feature android:name="android.hardware.gps"

        android:required="false"/>

<uses-feature android:name="android.hardware.microphone"

        android:required="false"/>

如果,設置爲true,你的程序可能就不會出現在電視設備選項,和出現在tv設備的主屏幕上。

8. 權限permissions 和硬件特性

Permission 權限 Implied hardware feature需要硬件特性

--------------------------------------------------------------

RECORD_AUDIO android.hardware.microphone

CAMERA android.hardware.camera and  android.hardware.camera.autofocus

ACCESS_COARSE_LOCATION android.hardware.location and android.hardware.location.network

ACCESS_FINE_LOCATION android.hardware.location and android.hardware.location.gps

8.1 檢查系統是否支持這些硬件特性

// 檢查是否支持電話特性

if (getPackageManager().hasSystemFeature("android.hardware.telephony")) {

    Log.d("HardwareFeatureTest", "Device can make phone calls");

}

// 檢查是否支持屏幕滑動

if (getPackageManager().hasSystemFeature("android.hardware.touchscreen")) {

    Log.d("HardwareFeatureTest", "Device has a touch screen.");

}

8.2 Touch screen android不支持的觸摸屏,因爲電視觀看環境不統一。

8.3 Camera ,雖然沒有攝像頭功能,但是還是支持圖片的查看和編輯。

<uses-feature android:name="android.hardware.camera" android:required="false" />

// Check if the camera hardware feature is available.

if (getPackageManager().hasSystemFeature("android.hardware.camera")) {

    Log.d("Camera test", "Camera available!");

} else {

    Log.d("Camera test", "No camera available. View and edit features only.");

}

8.4 GPS功能

android不支持GPS功能,但是你還是可以要求用戶搜索一個地址配置到電視設備上。,

// Request a static location from the location manager

LocationManager locationManager = (LocationManager) this.getSystemService(

        Context.LOCATION_SERVICE);

Location location = locationManager.getLastKnownLocation("static");

// Attempt to get postal or zip code from the static location object

Geocoder geocoder = new Geocoder(this);

Address address = null;

try {

  address = geocoder.getFromLocation(location.getLatitude(),

          location.getLongitude(), 1).get(0);

  Log.d("Zip code", address.getPostalCode());

} catch (IOException e) {

  Log.e(TAG, "Geocoder error", e);

}

9 手持設備電視控制器 Handling Controllers

  

 


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章