首页 > 解决方案 > Android 10 上的两个类似的意图过滤器

问题描述

我有一个应用程序,它有两个可以处理android.intent.action.GET_CONTENT动作的活动:

<!-- activity 1 -->
        <activity android:icon="@drawable/choose_video"
                  android:label="@string/choose_video"
                  android:name=".activity.ChooseVideoActivity">
            <intent-filter>
                <category android:name="android.intent.category.DEFAULT"/>
                <data android:mimeType="application/sample.get.video"/>
                <action android:name="android.intent.action.GET_CONTENT"/>
            </intent-filter>
        </activity>

<!-- activity 2 -->

        <activity android:icon="@drawable/record_video"
                  android:label="@string/record_video"
                  android:name=".activity.RecordVideoActivity">
            <intent-filter>
                <category android:name="android.intent.category.DEFAULT"/>
                <data android:mimeType="application/sample.get.video"/>
                <action android:name="android.intent.action.GET_CONTENT"/>
            </intent-filter>
        </activity>

我正在使用以下代码启动选择器:

Intent sendIntent = new Intent(Intent.ACTION_GET_CONTENT);
sendIntent.setType("application/sample.get.video");
sendIntent.putExtra(Intent.EXTRA_MIME_TYPES, new String[]{"video/*"});
startActivityForResult(Intent.createChooser(sendIntent, null), CODE_VIDEO);

在 10 之前的 Android 版本(api ver. <= 28)上一切正常:如果安装了 Files 应用程序,那么它会打开 Appdrawer 菜单中的我的 2 个活动以及可以处理此操作的其他应用程序(通常是 Google Drive) )。如果没有“文件”应用程序,则会出现选择器。但在 Android 10 上,它的行为有所不同:它只显示我的应用程序中的一项活动,而不是两项。

问题是,有没有人知道导致这种行为的 Android 10 中究竟发生了什么变化,并且可能知道这个问题的解决方案。或者,或者,如何使用其他方法实现类似的行为(在选择视频时在文件应用程序的菜单中显示我的应用程序中的 2 个图标)

标签: javaandroidandroid-manifest

解决方案


推荐阅读