How to make an apk can be used both in mobile and android-TV?

南笙酒味 提交于 2019-12-24 03:42:29

问题


Now I'm developping an appliction for both mobile and android-TV.According to the android develop guide, it is possible to do that.

For some reasons, I have developed two applications individually. 

Is it just simply merge two application's sources to archive that? Or is there something need to take care of ?


回答1:


In your Android Manifest you have to decorate your App Activity and TV Activity in a slightly different manner:

Here is how you decorate you App Activity

<activity
    android:name=".player.app.LaunchActivity"
    android:label="@string/app_name">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

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

Here is how you decorate you TV Activity

<activity
    android:name=".player.tv.TvActivity"
    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>
  • Note the use of the Leanback Theme and the Category intent for LEANBACK_LAUNCHER

Also be sure to restrict and unneeded features

<uses-feature
    android:name="android.hardware.touchscreen"
    android:required="false" />
<uses-feature
    android:name="android.hardware.faketouch"
    android:required="false" />
<uses-feature
    android:name="android.hardware.telephony"
    android:required="false" />
<uses-feature
    android:name="android.hardware.camera"
    android:required="false" />
<uses-feature
    android:name="android.hardware.camera.front"
    android:required="false" />
<uses-feature
    android:name="android.hardware.bluetooth"
    android:required="false" />
<uses-feature
    android:name="android.hardware.nfc"
    android:required="false" />
<uses-feature
    android:name="android.hardware.location.gps"
    android:required="false" />
<uses-feature
    android:name="android.hardware.microphone"
    android:required="false" />
<uses-feature
    android:name="android.hardware.sensor"
    android:required="false" />

And add a Banner to your Application declaration

<application
    android:name=".library.core.MainApplication"
    android:allowBackup="true"
    android:banner="@drawable/mythtv_logo"
    android:icon="@drawable/ic_mythtv"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >



回答2:


Yes, both mobile and TV specific code can be packaged in the same APK. In fact, much of the non-UI code could in theory be shared between the two.



来源:https://stackoverflow.com/questions/31778829/how-to-make-an-apk-can-be-used-both-in-mobile-and-android-tv

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!