Android TV not starting LAUNCH_LEANBACK Activity
Asked Answered
K

1

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.

Kentigera answered 3/2, 2015 at 11:40 Comment(9)
Yes, that's substantially correct. Isn't it working?Gipps
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.Pomeranian
@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.Kentigera
having the same problem, have no clue with that solution tho.Numskull
@y_nk, in Android Studio you Edit your run configurations i.sstatic.net/L2JdA.jpg , create separate config for TV and for mobile by explicitly specifying the Launch activity fieldKentigera
actually i found out that my problem was different. if interested, read : corochann.com/…Numskull
@Numskull The solution specified in the url you've provided works for me! Thank you!Bywaters
The link died can you provide the solution that was necessary? Here the Phone MainActivity is launched on Android TV no matter whatSextet
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 issuesKentigera
F
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

Fimbria answered 21/7, 2021 at 21:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.