如何将我的应用程序转换为 Android TV 应用程序? [英] How to convert my app to an Android TV app?
问题描述
我有一个带有 2 个视图(屏幕)的简单 Android 应用程序.我正在尝试让我的应用程序也能在 Android TV 上运行.我不知道我做错了什么,但是当我在模拟器上运行我的应用时,我没有看到我的应用的标志.
I have a simple Android application with 2 views (screens). I'm trying to make my app working on Android TV as well. I don't know what am I doing wrong, but when I run my app on an emulator I don't see my app's logo.
我的清单文件有什么问题:
What is wrong in my manifest file:
<?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>
推荐答案
尝试检查您的清单、您的图标(位置和大小)和您的应用程序 gradle 文件.我尝试使用基本活动(android)创建一个项目,然后添加:
Try checking your manifest, your icon (location and size) and your app gradle file. I tried creating a project with a basic activity(android) then added:
compile 'com.android.support:recyclerview-v7:23.4.0'
compile 'com.android.support:leanback-v17:23.4.0'
对于安卓电视支持并更新了我的清单:
For android TV support and updated my manifest:
<?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>
这是电视模拟器的示例屏幕截图.注意:我不拥有图标图像,仅用于测试目的.
Here is the sample screenshot of the TV emulator. NOTE: I do not own the icon image, it is for testing purposes only.
这里是项目树供参考:
参考:
这篇关于如何将我的应用程序转换为 Android TV 应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!