Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android TV not starting LAUNCH_LEANBACK Activity

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.

like image 931
Mickey Tin Avatar asked Feb 03 '15 11:02

Mickey Tin


1 Answers

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

like image 188
AliSh Avatar answered Oct 07 '22 16:10

AliSh