我正在开发一个汽车操作系统媒体应用程序,但对于我的项目,运行后我总是在模拟器上看到两个相同的图标。由于我的项目是一个汽车操作系统应用程序,因此没有 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'
}
最佳答案
Android 汽车平台显示两个图标,因为您的应用程序有两个 MediaBrowserService(AutomotiveMusicService 和 MusicService)。
汽车平台根据 Intent 过滤器“android.media.browse.MediaBrowserService”扫描平台中安装的媒体应用程序,因此有两个图标。
关于android - 运行后一个应用程序有两个相同的图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62368721/