简体   繁体   English

我们可以创建在 Android 电视、平板电脑和 Android 手机上运行的应用程序吗?

[英]Can we create application which run on Android TV ,tablet and Android Phones?

I just want to know that can i create one android studio project which can run on Android TV, tablets, and Android smartphones?我只想知道我可以创建一个 android 工作室项目,它可以在 Android 电视、平板电脑和 Android 智能手机上运行吗?

Yes you can.While starting new project there is option for selecting template for Phone and tablet,Wear OS,Android TV etc like below image.是的,你可以。在开始新项目时,可以选择为手机和平板电脑、Wear OS、Android 电视等选择模板,如下图所示。 在此处输入图像描述

You need to implement the leanback support library in order for your app to support Android TV.为了让您的应用程序支持 Android TV,您需要实现leanback 支持库。

Check this for the implementation steps.检查以了解实施步骤。

Yes, you can.是的你可以。 Your app needs to declare the intent filter for both mobile and Android TV.您的应用需要为移动设备和 Android 电视声明意图过滤器。 Typically these should be different activities since the UI is usually different, but they can also point to the same activity if you're programmatically choosing the correct UI based on the device.通常这些应该是不同的活动,因为 UI 通常是不同的,但如果您基于设备以编程方式选择正确的 UI,它们也可以指向相同的活动。

Here's an example of the manifest:这是清单的示例:

<application
  android:banner="@drawable/banner" >
  ...
  <activity
    android:name="com.example.android.MainActivity"
    android:label="@string/app_name" >

    <intent-filter>
      <action android:name="android.intent.action.MAIN" />
      <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
  </activity>

  <activity
    android:name="com.example.android.TvActivity"
    android:label="@string/app_name"
    android:theme="@style/Theme.Leanback">

    <intent-filter>
      <action android:name="android.intent.action.MAIN" />
      <category android:name="android.intent.category.LEANBACK_LAUNCHER" />
    </intent-filter>

  </activity>
</application>

If you're starting a completely fresh Android Studio project, I'd recommend starting with a mobile template first and then manually updating the manifest.如果您要开始一个全新的 Android Studio 项目,我建议您先从移动模板开始,然后手动更新清单。 See the getting started guide for more info, including the intent filter, the banner, the "leanback" feature, and more.有关更多信息,请参阅入门指南,包括意图过滤器、横幅、“leanback”功能等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM