15
Android TV 入門 Ascii @ KKBOX

Android tv get started

Embed Size (px)

Citation preview

Page 1: Android tv get started

Android TV 入門

Ascii @ KKBOX

Page 2: Android tv get started

ADT-1 Nexus Player

Page 3: Android tv get started

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'

}

Page 4: Android tv get started

compileSdkVersion VS buildToolsVersion

Page 5: Android tv get started

Nexus Player Controller

Page 6: Android tv get started

Resolution

Page 7: Android tv get started

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>

Page 8: Android tv get started

Add TV Support 2

Page 9: Android tv get started

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)

Page 10: Android tv get started

Leanback Library

1. BrowseFragment

2. SearchFragment

3. DetailFragment

4. PlayFragmen

Page 11: Android tv get started

BrowseFragment

public ListRow(HeaderItem header, ObjectAdapter adapter)

setBadgeDrawable(/*res*/);

Page 12: Android tv get started

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)

Page 13: Android tv get started

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 */)

}

Page 14: Android tv get started

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);

}

}

Page 15: Android tv get started

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