Search code examples
androidandroid-tv

How to make an apk can be used both in mobile and android-TV?


Now I'm developping an appliction for both mobile and android-TV.According to the android develop guide, it is possible to do that.

For some reasons, I have developed two applications individually. 

Is it just simply merge two application's sources to archive that? Or is there something need to take care of ?


Solution

  • In your Android Manifest you have to decorate your App Activity and TV Activity in a slightly different manner:

    Here is how you decorate you App Activity

    <activity
        android:name=".player.app.LaunchActivity"
        android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
    
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    

    Here is how you decorate you TV Activity

    <activity
        android:name=".player.tv.TvActivity"
        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>
    
    • Note the use of the Leanback Theme and the Category intent for LEANBACK_LAUNCHER

    Also be sure to restrict and unneeded features

    <uses-feature
        android:name="android.hardware.touchscreen"
        android:required="false" />
    <uses-feature
        android:name="android.hardware.faketouch"
        android:required="false" />
    <uses-feature
        android:name="android.hardware.telephony"
        android:required="false" />
    <uses-feature
        android:name="android.hardware.camera"
        android:required="false" />
    <uses-feature
        android:name="android.hardware.camera.front"
        android:required="false" />
    <uses-feature
        android:name="android.hardware.bluetooth"
        android:required="false" />
    <uses-feature
        android:name="android.hardware.nfc"
        android:required="false" />
    <uses-feature
        android:name="android.hardware.location.gps"
        android:required="false" />
    <uses-feature
        android:name="android.hardware.microphone"
        android:required="false" />
    <uses-feature
        android:name="android.hardware.sensor"
        android:required="false" />
    

    And add a Banner to your Application declaration

    <application
        android:name=".library.core.MainApplication"
        android:allowBackup="true"
        android:banner="@drawable/mythtv_logo"
        android:icon="@drawable/ic_mythtv"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >