首页 > 解决方案 > 运行后一个应用程序的两个相同图标

问题描述

我正在开发一个 Automotive OS Media 应用程序,但对于我的项目,运行后我的模拟器上总是会出现两个相同的图标。由于我的项目是汽车操作系统应用程序,因此没有 android.intent.action.MAIN 和 android.intent.category.LAUNCHER - 我的意思是,它们没有重复导致我的问题。

我的项目有两个模块 - 一个是汽车应用程序,另一个是媒体服务库(命名为 common)。下面是两部分的AndroidManifest.xml和build.gradle文件。

AndroidManifest.xml(汽车)

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

    <uses-feature
        android:name="android.hardware.type.automotive"
        android:required="true" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.AppCompat">

        <activity android:name=".SignInActivity">
            <intent-filter>
                <action android:name="android.intent.action.ACTION_SIGN_IN" />
            </intent-filter>
        </activity>

        <service
            android:name=".AutomotiveMusicService"
            android:enabled="true"
            android:exported="true">
            <intent-filter>
                <action android:name="android.media.browse.MediaBrowserService"/>
            </intent-filter>
        </service>

    </application>

</manifest>

build.gradle(汽车)

plugins {
    id 'com.android.application'
}

android {
    compileSdkVersion 29

    defaultConfig {
        applicationId "com.example.automotivemusic"
        minSdkVersion 28
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation project(path: ':common')
    implementation 'androidx.media:media:1.1.0'
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'com.google.android.material:material:1.1.0'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

AndroidManifest.xml(常用)

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

    <application>
        <service
            android:name="com.example.common.MusicService"
            android:exported="true">
            <intent-filter>
                <action android:name="android.media.browse.MediaBrowserService" />
            </intent-filter>
        </service>
    </application>

</manifest>

build.gradle(通用)

plugins {
    id 'com.android.library'
}

android {
    compileSdkVersion 29

    defaultConfig {
        minSdkVersion 28
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        consumerProguardFiles "consumer-rules.pro"
    }

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

dependencies {
    implementation 'androidx.media:media:1.1.0'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

标签: androidandroid-studioandroid-automotive

解决方案


Android 汽车平台显示两个图标,因为您的应用程序有两个 MediaBrowserService(AutomotiveMusicService 和 MusicService)。

汽车平台根据intent-filter“android.media.browse.MediaBrowserService”扫描安装在平台中的媒体应用程序,因此有两个图标。


推荐阅读