13

I want to create a single apk that will be compatible with mobile and TV. As I understand I should specify the launcher activity for both platforms in manifest, one for mobile with <category android:name="android.intent.category.LAUNCHER" />, another for TV with <category android:name="android.intent.category.LEANBACK_LAUNCHER" /> intent filter. And Android should automatically pick the right activity when launching, depending on platform, right ? Or I should add some java code and start my TV activity from code ? Currently it launch my mobile activity when using android TV emulator. Below is my manifest file :

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.mypackagename"
    android:versionCode="142"
    android:versionName="2.0.142" >

    <uses-sdk tools:overrideLibrary="android.support.v17.leanback"/>

    <uses-permission android:name="android.permission.INTERNET" />

    <uses-feature
        android:name="android.hardware.microphone"
        android:required="false" />

    <uses-feature
        android:name="android.hardware.bluetooth"
        android:required="false" />

    <!-- TV -->
    <uses-feature
        android:name="android.hardware.touchscreen"
        android:required="false" />

    <uses-feature android:name="android.software.leanback"
        android:required="false" />

    <application
        android:name="com.mypackagename.App"
        android:allowBackup="true"
        android:hardwareAccelerated="true"
        android:icon="@drawable/ic_launcher"
        tools:replace="android:icon"
        android:label="@string/app_name"
        android:banner="@drawable/ic_launcher"
        android:largeHeap="true"
        android:supportsRtl="false"
        android:theme="@style/AppTheme" >

        <activity
            android:name="com.mypackagenametv.MainTVActivity"
            android:theme="@style/TVAppTheme"
            android:label="@string/app_name"
            android:logo="@drawable/ic_launcher"
            android:screenOrientation="landscape" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LEANBACK_LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.mypackagenametv.PlayerActivity"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" />
        <activity android:name="com.mypackagenametv.DetailsActivity" />

        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />

        <activity
            android:name="com.mypackagename.ui.activities.MainActivity"
            android:label="@string/app_name"
            android:launchMode="singleTask"
            android:screenOrientation="sensorLandscape"
            android:windowSoftInputMode="stateHidden|adjustResize|adjustPan" >
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.mypackagename.ui.activities.SplashActivity"
            android:configChanges="keyboardHidden|orientation|screenSize"
            android:label="@string/app_name"
            android:screenOrientation="sensorLandscape"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
 .... other activities
    </application>

</manifest>

SOLVED

My mobile activity was specified explicitly in Run configurations as launcher. After I set Launch default Activity everything works fine.

Mickey Tin
  • 3,408
  • 10
  • 42
  • 71
  • 1
    Yes, that's substantially correct. Isn't it working? – Sebastiano Feb 03 '15 at 12:00
  • 3
    When you set the Run configuration as default, does the TV emulator run the TV activity and the phone emulator run the phone activity? If I set the Run configuration to start the default activity, both emulators start the phone activity. – Jose Gómez Apr 27 '15 at 09:43
  • 5
    @JoseGómez, it might not work as expected with Default configurations, you better specify explicit activity for TV and for Mobile (create 2 run configurations). However when launching from generated APK it works correctly and pick the proper activity. – Mickey Tin Apr 27 '15 at 11:37
  • having the same problem, have no clue with that solution tho. – y_nk May 25 '16 at 10:00
  • @y_nk, in Android Studio you Edit your run configurations http://i.stack.imgur.com/L2JdA.jpg , create separate config for TV and for mobile by explicitly specifying the Launch activity field – Mickey Tin May 25 '16 at 10:25
  • 1
    actually i found out that my problem was different. if interested, read : http://corochann.com/recent-update-of-leanbacklauncher-home-app-775.html – y_nk May 26 '16 at 12:58
  • 2
    @y_nk The solution specified in the url you've provided works for me! Thank you! – Alejandro Traver Nov 04 '19 at 16:21
  • The link died can you provide the solution that was necessary? Here the Phone MainActivity is launched on Android TV no matter what – timr Jan 24 '21 at 12:38
  • Hi @tim, this is the Run configuration issue only (Android IDE or Eclipse). You may want to create a separate run config("Play" button) for mobile and for TV with dedicated activities. Also installing from the apk file works with no issues – Mickey Tin Jan 24 '21 at 14:09

1 Answers1

0

I had the same problem. The solution was defining another configuration for Android TV.

Step1: Edit Configuration enter image description here

Step2: Copy Android app configuration enter image description here

Step3: Change configuration name to tvApp

Step4: Change Launch Activity to your TV activity enter image description here

AliSh
  • 10,085
  • 5
  • 44
  • 76