支持 Android Auto 和 android Wear 的现有应用程序

问题描述 投票:0回答:1

我有一个 android 代码库,其中包含 Android TV 和 Android mobile 的项目。它基本上播放广播,它也支持近距离播放。现在的要求是这个应用程序应该在Android Wear Android Auto上运行。

我不知道下一步应该做什么来更改此代码库以支持 Android auto 和 Android Wear。

我是否应该创建另一个磨损和汽车项目,或者可以修改现有项目,如果现有项目可以支持磨损和汽车,您能否告诉我步骤或分享我的链接,我可以按照该链接使我的项目支持汽车和穿。

下面是我现有的菜单文件

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

    <supports-screens android:smallScreens="false"
        android:normalScreens="false"
        android:largeScreens="true"
        android:xlargeScreens="true"/>
    <uses-feature
        android:name="android.software.leanback"
        android:required="true" />
    <uses-feature
        android:name="android.hardware.touchscreen"
        android:required="false" />

    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
    <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
    <uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM"
        tools:ignore="LeanbackUsesWifi" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />

    <uses-permission android:name="android.permission.BLUETOOTH" />
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
    <!-- Needed only if your app looks for Bluetooth devices.
             If your app doesn't use Bluetooth scan results to derive physical
             location information, you can strongly assert that your app
             doesn't derive physical location. -->
    <uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
    <!-- Needed only if your app makes the device discoverable to Bluetooth
      devices. -->
    <uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" />
    <!-- Needed only if your app communicates with already-paired Bluetooth
           devices. -->
    <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
    <!--bibo01 : hardware option-->
    <uses-feature android:name="android.hardware.bluetooth" android:required="false"/>
    <uses-feature android:name="android.hardware.bluetooth_le" android:required="false"/>


    <queries>
        <package android:name="com.montrealgreektv.app.player" />
    </queries>

    <application
        android:name=".application.App"
        android:allowBackup="true"
        android:banner="@mipmap/ic_banner"
        android:dataExtractionRules="@xml/data_extraction_rules"
        android:fullBackupContent="@xml/backup_rules"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.MontrealGreek"
        android:usesCleartextTraffic="true"
        tools:ignore="GoogleAppIndexingWarning"
        tools:targetApi="31">
        <activity
            android:name=".tv.TvPlayerActivity"
            android:exported="false" />
        <activity
            android:name=".tv.TvMainActivity"
            android:exported="false" />
        <activity
            android:name=".tv.TvSplashActivity"
            android:exported="false"
            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=".news.NewsActivity"
            android:exported="false"
            android:label="@string/title_activity_news"
            android:theme="@style/Theme.MontrealGreek.NoActionBar" />
        <activity
            android:name=".radio.RadioPlayerActivity"
            android:exported="false" />
        <activity
            android:name=".player.PlayerActivity"
            android:exported="true"
            android:launchMode="singleTask"
            android:screenOrientation="landscape">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
            </intent-filter>
        </activity>
        <activity
            android:name=".home.MainActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />

                <data android:scheme="montrealgreektv" />
            </intent-filter>
        </activity>
        <activity
            android:name=".home.SplashActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                 <category android:name="android.intent.category.LEANBACK_LAUNCHER"/>
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity android:name=".radio.DeviceListDialogFragment"
            android:exported="false"
            android:screenOrientation="portrait"/>

        <meta-data
            android:name="com.google.android.gms.cast.framework.OPTIONS_PROVIDER_CLASS_NAME"
            android:value="com.montrealgreektv.app.player.CastOptionsProvider" />

        <service android:name=".service.MyService" />

        <uses-library
            android:name="org.apache.http.legacy"
            android:required="false" />
    </application>

</manifest>

我的gradle代码

plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'
}

android {
    namespace 'com.montrealgreektv.app'
    compileSdk 33

    defaultConfig {
        applicationId "com.montrealgreektv.app"
        minSdk 23
        targetSdk 33
        //for mobile
//        versionCode 8
//        versionName "1.02"

        //for TV
        versionCode 9
        versionName "1.03"

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }

    dataBinding {
        enabled = true
    }
    buildFeatures {
        viewBinding true
    }
}

dependencies {

    //noinspection GradleCompatible
    implementation 'com.android.support.constraint:constraint-layout:2.0.4'
    implementation 'com.google.android.material:material:1.9.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    implementation 'androidx.navigation:navigation-fragment-ktx:2.6.0'
    implementation 'androidx.navigation:navigation-ui-ktx:2.6.0'
    implementation 'androidx.leanback:leanback:1.0.0'
    testImplementation 'junit:junit:4.13.2'
   
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'


    implementation 'androidx.appcompat:appcompat:1.6.1'
    implementation 'com.intuit.sdp:sdp-android:1.1.0'

    // LiveData and ViewModel
    implementation "androidx.lifecycle:lifecycle-common-java8:2.1.0"
    implementation "androidx.lifecycle:lifecycle-extensions:2.1.0"

    // RxJava
    implementation 'io.reactivex.rxjava2:rxjava:2.2.15'
    implementation 'io.reactivex.rxjava2:rxandroid:2.0.2'

    // Retrofit
    implementation 'com.squareup.retrofit2:retrofit:2.9.0'
    // Gson Converter
    implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
    // Glide
    implementation 'com.github.bumptech.glide:glide:4.14.2'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.14.2'

    implementation 'com.google.android.exoplayer:exoplayer:2.18.2'
    implementation 'com.google.android.exoplayer:exoplayer-dash:2.18.2'
    implementation 'com.google.android.exoplayer:exoplayer-smoothstreaming:2.18.2'
    implementation 'com.google.android.exoplayer:exoplayer-core:2.18.2'
    implementation 'com.google.android.exoplayer:exoplayer-hls:2.18.2'
    implementation 'com.google.android.exoplayer:exoplayer-ui:2.18.2'
    implementation 'com.google.android.exoplayer:extension-cast:2.18.2'

    implementation 'com.github.bumptech.glide:glide:4.14.2'
    implementation 'androidx.mediarouter:mediarouter:1.2.5'

    implementation 'androidx.leanback:leanback:1.0.0'
}

请指导我使此代码支持汽车和穿戴

android wear-os android-auto
1个回答
0
投票

对于汽车,请查看为汽车构建媒体应用程序添加对 Android Auto 的支持。对于 Wear,请查看 Wear 媒体库

© www.soinside.com 2019 - 2024. All rights reserved.