I'm trying to create an AndroidStudio project that supports both Android (phone/tablet) and AndroidTV. The goal is to have similar functionality on the Phone/tablet and AndroidTV, while one not needing the other to operate, and reusing code.
When I create a new project, do I:
I've tried b) but both the phone (5.0) and ADT-1 just get the same layout.
Below is my manifest file (MainActivity is placed before MainActivityTV). When I run it, both phone and ADT-1 load the phone layout. But, when I put MainActivityTV before MainActivity, both my phone and ADT-1 load the leanback layout. How do I make it so that phone only loads MainActivity, and the ADT-1 only loads MainActivityTV?
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.androidretrofitwithtv" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-feature
android:name="android.hardware.touchscreen"
android:required="false" />
<uses-feature
android:name="android.software.leanback"
android:required="false" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:banner="@drawable/app_icon_your_company"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivityTV"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|navigation"
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>
<activity android:name=".DetailsActivity" />
<activity android:name=".PlaybackOverlayActivity" />
<activity android:name=".BrowseErrorActivity" />
</application>
</manifest>
Android Studio is the official Integrated Development Environment (IDE) for Android app development, based on IntelliJ IDEA .
Use Android Studio and Java to write Android appsYou write Android apps in the Java programming language using an IDE called Android Studio. Based on JetBrains' IntelliJ IDEA software, Android Studio is an IDE designed specifically for Android development.
Leanback: The v17 Leanback Support Library is a standard Android support library focused on providing APIs and widgets to simplify the development of TV apps. Most of the components used in a Leanback-enabled project are contained in this library. RecyclerView: This library provides the RecyclerView class.
Yes, it is possible to have one APK file for both phone/tablet and Android TV app because TV apps use the same structure as those for phones and tablets. This similarity means you can modify your existing apps to also run on TV devices or create new apps based on what you already know about building apps for Android.
Before you begin building apps for TV, you must: Update your SDK tools to version 24.0.0 or higher. The updated SDK tools enable you to build and test apps for TV. Update your SDK with Android 5.0 (API 21) or higher. The updated platform version provides new APIs for TV apps. Create or update your app project. In order to access new APIs for TV devices, you must create a project or modify an existing project that targets Android 5.0 (API level 21) or higher.
An application intended to run on TV devices must declare a launcher activity for TV in its manifest using a CATEGORY_LEANBACK_LAUNCHER intent filter. This filter identifies your app as being enabled for TV, and is required for your app to be considered a TV app in Google Play. Declaring this intent also identifies which activity in your app to launch when a user selects its icon on the TV home screen.
If you are modifying an existing app for use on TV, your app should not use the same activity layout for TV that it does for phones and tablets. The user interface of your TV app (or TV portion of your existing app) should provide a simpler interface that can be easily navigated using a remote control from a couch. For guidelines on designing an app for TV, see the TV Design guide. For more information on the minimum implementation requirements for interface layouts on TV, see Building TV Layouts.
The following code snippet shows how to include this intent filter in your manifest:
<application
android:banner="@drawable/banner" >
...
<activity
android:name="com.example.android.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<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>
</application>
Declare that your app uses the Leanback user interface required by Android TV. If you are developing an app that runs on mobile (phones, wearables, tablets, etc.) as well as Android TV, set the required attribute value tofalse. If you set the required attribute value to true, your app will run only on devices that use the Leanback UI.
<manifest>
<uses-feature android:name="android.software.leanback"
android:required="false" />
...
</manifest>
The manifest of your TV app must declare that a the android.hardware.touchscreen feature is not required. This setting identifies your app as being able to work on a TV device, and is required for your app to be considered a TV app in Google Play. The following code example shows how to include this manifest declaration:
<manifest>
<uses-feature android:name="android.hardware.touchscreen"
android:required="false" />
...
</manifest>
An application must provide a home screen banner for each localization if it includes a Leanback launcher intent filter. The banner is the app launch point that appears on the home screen in the apps and games rows. Describe the banner in the manifest as follows:
<application
...
android:banner="@drawable/banner" >
...
</application>
Use the android:banner attribute with the tag to supply a default banner for all application activities, or with the tag to supply a banner for a specific activity.
See Banners in the UI Patterns for TV design guide.
The Android SDK includes support libraries that are intended for use with TV apps. These libraries provide APIs and user interface widgets for use on TV devices. The libraries are located in the/extras/android/support/ directory. Here is a list of the libraries and their general purpose:
You can do this by detecting the type of device your running on. I would do this in your MainActivity by checking the UImode and then starting the TVActivity if its running on Tv like below
uiMode = (UiModeManager) getSystemService(UI_MODE_SERVICE)
if(uiMode.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION){
//then start TvActivity here
...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With