androidtelevision

best practice for Android app for Mobile and TV screen


i have android app which runs on mobile normally, but i need to make new design for this app for TV screen, this new design requires new widgets and new java code which is different from the code being used for mobile phone.

what is the best practice to do that? i already read about how to detect if the app is running on tv or mobile but i don't think this is the best practice to do that.


Solution

  • You can find whole info here https://developer.android.com/training/tv/start/start, but I would also share some pieces of advice:

    1. Don't use Recycler view within TV app, use VerticalGridView instead.
    2. Adding a 5% margin of 48dp on the left and right edges and 27dp on the top and bottom edges to a layout ensures that screen elements in that layout will be within the overscan safe area.
    3. UI elements are focusable – this is a completely unique concept when developing remote-controlled apps compared to how mobile apps are used. The entire process of handling focus of the UI elements can be a challenge in itself, and is quite a ‘culture change’ from mobile. You need to develop the underlying logic of how to highlight focus elements and also to devise and develop for the logic of how the user moves between elements and blocks of elements with the 5-key RCU.
    4. Obviously all swipes and gestures are not going to work, so you should rewrite this kind of logic.

    This is the easiest way to find out the device's type:

     val uiModeManager = getSystemService(UI_MODE_SERVICE) as UiModeManager
     if (uiModeManager.currentModeType == Configuration.UI_MODE_TYPE_TELEVISION) {
         //it is TV
     } else {
         //it is mobile
     }