如何将我的应用转换为Android TV应用?

4

我有一个简单的Android应用程序,有2个视图(屏幕)。

我正在尝试让我的应用程序在Android TV上工作。但是我不知道我做错了什么,当我在模拟器上运行我的应用程序时,我看不到我的应用程序的标志。

我的清单文件中有什么问题:

<?xml version="1" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="xxx.flagmaster">
    <uses-feature android:name="android.software.leanback"
        android:required="false" />
    <uses-feature android:name="android.hardware.touchscreen"
        android:required="false" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <category android:name="android.intent.category.LEANBACK_LAUNCHER"/>
    <application
        android:allowBackup="true"
        android:icon="@drawable/flagmasterlogo"
        android:label="@string/app_name"
        android:banner="@drawable/flagmastertv"
        android:supportsRtl="true">
        android:theme="@style/AppTheme">    
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LEANBACK_LAUNCHER" />
            </intent-filter>
        </activity>    
        <activity android:name=".FlagShowActivity"  
          android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize">
            <meta-data
                android:name="com.google.android.gms.version"
                android:value="@integer/google_play_services_version" />
            <intent-filter>    
                <category android:name="android.intent.category.LEANBACK_LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>
1个回答

3

请检查您的清单、图标(位置和大小)和应用 gradle 文件。我尝试创建一个带有基本活动(Android)的项目,然后添加:

compile 'com.android.support:recyclerview-v7:23.4.0'
compile 'com.android.support:leanback-v17:23.4.0'

为了支持Android TV并更新我的清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="package_name.tvapp">

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

    <!-- TV app need to declare touchscreen not required -->
    <uses-feature
        android:name="android.hardware.touchscreen"
        android:required="false" />

    <!--
     true:  your app runs on only TV
     false: your app runs on phone and TV
    -->
    <uses-feature
        android:name="android.software.leanback"
        android:required="false" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/icon"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LEANBACK_LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

这是电视模拟器的示例截图。注意:我不拥有图标图片,仅用于测试目的。

enter image description here

以下是项目树供参考:

enter image description here

参考资料:


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接