【问题标题】:Android manifest merging: removing LAUNCHER intent-filter doesn't take effectAndroid清单合并:删除LAUNCHER意图过滤器不生效
【发布时间】:2015-09-24 13:49:52
【问题描述】:

在我的 android 应用程序中,我使用了一个库项目,并使用了其中一个活动。但是在库项目中,该活动具有 MAIN 操作和 LAUNCHER 类别意图过滤器。所以我将该活动添加到我的清单中并删除了意图过滤器。清单似乎已正确合并到 build/intermediates/manifests/full/debug/AndroidManifest.xml 中,并且活动看起来如预期(没有意图过滤器):

    <activity
        android:name="com.michaelrnovak.util.logger.Logger"
        android:configChanges="orientation"
        android:label="@string/show_log" >
    </activity>

但是,当我在模拟器中从 AndroidStudio 启动应用程序时,会启动库的 Logger 活动而不是我的 AlertsActivity。我做错了什么?

这是库的清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.michaelrnovak.util.logger"
      android:versionCode="8"
      android:versionName="1.5">
    <uses-permission android:name="android.permission.READ_LOGS" />
    <application
        android:icon="@drawable/icon"
        android:label="@string/app_name"
        android:theme="@style/AppTheme">
        <activity android:name=".Logger"
                  android:label="@string/app_name"
                  android:configChanges="orientation">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>
    <uses-sdk android:minSdkVersion="7" />
</manifest> 

并且我的应用清单具有以下相关活动定义:

    <activity
        android:name=".AlertsActivity"
        android:configChanges="orientation|keyboardHidden|screenSize"
        android:label="@string/app_name"
        android:launchMode="singleTop" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />          </intent-filter>
    </activity>
    <activity android:name="com.michaelrnovak.util.logger.Logger"
        android:label="@string/show_log"
        android:configChanges="orientation"
        tools:replace="android:label"
        >
        <intent-filter tools:node="removeAll" />
    </activity>

【问题讨论】:

标签: android merge android-manifest intentfilter android-launcher


【解决方案1】:

您是否仅在类别节点上尝试过 tools:node="remove" ?根据我的经验,它似乎有效。

类似这样的:

<activity android:name="com.michaelrnovak.util.logger.Logger"
        android:label="@string/show_log"
        android:configChanges="orientation"
        tools:replace="android:label"
        >
        <intent-filter>
            <category   tools:node="remove" android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>

【讨论】:

  • 仅删除 &lt;category&gt; 对我不起作用,但同时删除 &lt;action&gt; 可以。 &lt;activity android:name="com.squareup.leakcanary.internal.DisplayLeakActivity"&gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.MAIN" tools:node="remove" /&gt; &lt;category android:name="android.intent.category.LAUNCHER" tools:node="remove" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; 这比我以前的有所改进。非常感谢!
  • @CommonsWare ,你最好发布一个答案,这样其他人会更容易看到这个解决方案
【解决方案2】:

在像你这样的情况下,我尝试了很多方法。我发现我必须在Activity 节点中添加tools:node="replace" 才能删除intent-filter 的特定actioncategory。试试这个:)

<activity 
    android:name="com.michaelrnovak.util.logger.Logger"
    android:label="@string/show_log"
    android:configChanges="orientation"
    tools:replace="android:label"
    tools:node="replace">

    <!-- Rewrite the intent-filter you want -->
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

【讨论】:

  • 嘿,我有一个疑问。您刚刚使用了节点“replace”,但还添加了没有“remove”节点的意图过滤器。那么,它到底对你有什么作用呢?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-05-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-23
相关资源
最近更新 更多