android tv get started

Post on 15-Jul-2015

809 Views

Category:

Technology

1 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Android TV 入門

Ascii @ KKBOX

ADT-1 Nexus Player

Android TV SDK

android {

compileSdkVersion 21

buildToolsVersion "21.1.1"

defaultConfig {

minSdkVersion 21

targetSdkVersion 21

}

}

dependencies {

compile 'com.android.support:leanback-v17:21.0.2'

}

compileSdkVersion VS buildToolsVersion

Nexus Player Controller

Resolution

Add TV Support 1

<application

android:allowBackup="true"

android:icon="@drawable/ic_launcher"

android:label="@string/app_name"

android:banner="@drawable/app_banner"

android:theme="@style/AppTheme" >

</application>

<activity

android:name=".TVMainActivity"

android:screenOrientation="landscape" >

<intent-filter>

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

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

</intent-filter>

</activity>

Add TV Support 2

Common Errors

1. SDK Level (min 17)

2. Launch default Activity (Android Studio bug)

3. Unnecessary Resources (for mobile module)

4. uses-feature android:required="true" (false)

Leanback Library

1. BrowseFragment

2. SearchFragment

3. DetailFragment

4. PlayFragmen

BrowseFragment

public ListRow(HeaderItem header, ObjectAdapter adapter)

setBadgeDrawable(/*res*/);

DetailFragment

DetailsOverviewRow.setAction(new Action(long id, CharSequence label))

OnActionClickedListener.

onActionClicked(Action action)

if (action.getId() == OPEN)

else if (action.getId() == UNIN)

else if (action.getId() == UPD)

Create recommendations<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

<receiver

android:name=".recommendation.BootupActivity"

android:enabled="true"

android:exported="false" >

<intent-filter>

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

</intent-filter>

</receiver>

if (intent.getAction().endsWith(Intent.ACTION_BOOT_COMPLETED)) {

// startService(/* IntentService */) or getService(/* IntentService */)

}

Create recommendations

public class RecommendationsService extends IntentService {

@Override

protected void onHandleIntent(Intent intent) {

NotificationManager mNotificationManager = (NotificationManager)

getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);

Notification notification = new NotificationCompat.BigPictureStyle(

new NotificationCompat.Builder()).build();

mNotificationManager.notify(count, notification);

}

}

Reference

Design guideline

http://developer.android.com/design/tv/index.html

TV App Quality

http://developer.android.com/distribute/essentials/quality/tv.html

Publishing process

http://developer.android.com/distribute/googleplay/tv.html

Using the Leanback library

https://github.com/googlesamples/androidtv-Leanback

https://www.youtube.com/watch?v=72K1VhjoL98

top related