Coder Social home page Coder Social logo

androidtvdemo's Introduction

androidtvdemo

This project demonstrates the steps to be taken to port/create an app for Android TV. Compile this project as is and install it on to the TV. You can see that the app is not listed in the Home Screen app drawer. You can only open it from Settings -> Apps -> Downloaded Apps -> Android TvDemo. Experience its UI. You will find that the focus is not clear and navigation may not be as per your expectation.

Now start following the below steps to make it TV ready.

  1. Modify the Android Manifest file to add the leanback launcher intent to your activity. Without this, your app won't appear in the Home screen nor in the TV Play Store.

         <intent-filter>
             <action android:name="android.intent.action.MAIN" />
    
             <category android:name="android.intent.category.LEANBACK_LAUNCHER" />
         </intent-filter>
    
  2. Once you have added the intent to your manifest, you need to add a Home Banner of 320x180 px. Home Banner should carry the name of your application. Specify the reference to this banner in your Manifest under your activity: android:banner="@mipmap/home_tv"

Alt text

Now you should be able to see and launch your app from the Home Screen. Without the first 2 steps, your app wont be listed in the Home screen, app drawer.

  1. Now coming to the layout of your application. It will look like this:

Alt text

As you can see, it is difficult to identify from a distance, which is the currently focused button.

  1. So, you either need to add the leanback effect (the focused element will zoom out a bit) or draw a border around it or paint it with a different color. I have chosen the 3rd approach. This is how it looks now:

Alt text

You can see that the 'Left' button is highlighted in Red. To achieve this effect, I have applied the style style="@style/button_custom" to all the buttons. See /app/src/main/res/layout/activity_main.xml

  1. To handle D-Pad navigation:

    a. First you have to decide which view gets the focus on launch. You have to request it using view.requestFocus().

    b. Now once you set the focus, you have to control the navigation. If you press 'up' button of your remote, from the 'Bottom' button, the focus first goes to 'Right' button, then to the 'Top' button. In case, you want the focus to reach the 'Top' button directly from 'Bottom' button, you need to set buttonbottom.setNextFocusUpId(R.id.buttontop); Similarly, you can modify for the other views.

With these changes, your basic TV app is ready.

Further enhancements - Control from mobile

Once the basic TV app is ready, you can enhance it by having your mobile exchange data and controls with the TV. This can be done using NSD (generic) and Cast sdk. This project already has the files related to NSD already added in the folder /app/src/main/java/com/android/tv/androidtvapp/nsd.

You can follow the next project https://github.com/nikhiltiru/tv-mobilecontrol to make these enhancements.

androidtvdemo's People

Contributors

nikhiltiru avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.