Android意图过滤器在安装后无法正常工作

时间:2013-11-16 14:44:24

标签: android android-intent android-manifest

我的应用程序注册了一个意图过滤器来打开一种用于在用户之间共享数据的文件,这种方法工作正常,但有一个例外,如下所述。

在安装应用程序并在浏览器应用程序(例如DropBox Android应用程序)中单击导入文件后,应用程序第一次不会出现在“使用完整操作”对话框中。但是,如果再次尝试导入,则它可以正常工作 - 之后每次都可以。此外,如果应用程序在安装后至少打开一次,并且在尝试导入文件之前,它也可以正常工作。

可能值得注意的是,应用程序立即打开,无需通过“使用完整操作”对话框,并且无需将应用程序设置为默认应用程序。

用户经常会这样做,因为他们经常安装应用程序,然后立即尝试导入一些示例文件,因此应用程序会从一些内容开始。

如何确保应用程序在安装后立即收到意图?

这是我的清单文件:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="za.ac.sun.battlemanager"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="16" />

    <instrumentation
        android:name="android.test.InstrumentationTestRunner"
        android:targetPackage="za.ac.sun.battlemanager" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <provider
            android:name="za.ac.sun.battlemanager.datatransfer.CachedFileProvider"
            android:authorities="za.ac.sun.battlemanager.gmailattach.provider" >
        </provider>

        <!-- linkage for the test runner -->
        <uses-library android:name="android.test.runner" />

        <activity
            android:name="za.ac.sun.battlemanager.StartActivity"
            android:label="@string/app_name"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="za.ac.sun.battlemanager.ScenarioActivity"
            android:label="@string/app_name"
            android:parentActivityName="za.ac.sun.battlemanager.StartActivity"
            android:screenOrientation="landscape"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="za.ac.sun.battlemanager.StartActivity" />

            <intent-filter>

                <!--
                     <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />

                -->
            </intent-filter>
        </activity>
        <activity
            android:name="za.ac.sun.battlemanager.LoadActivity"
            android:label="@string/title_activity_load"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
        </activity>
        <activity
            android:name="za.ac.sun.battlemanager.CreateActivity"
            android:label="@string/title_activity_create"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
        </activity>
        <activity
            android:name="za.ac.sun.battlemanager.ExportActivity"
            android:label="@string/title_activity_export"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
        </activity>
        <activity
            android:name="za.ac.sun.battlemanager.ExportScenarioListActivity"
            android:label="@string/title_activity_export_scenario_list"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
        </activity>
        <activity
            android:name="za.ac.sun.battlemanager.ExportLibraryActivity"
            android:label="@string/title_activity_export_library"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
        </activity>
        <activity
            android:name="za.ac.sun.battlemanager.ExportScenarioActivity"
            android:label="@string/title_activity_export_scenario"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
        </activity>
        <activity
            android:name="za.ac.sun.battlemanager.ImportActivity"
            android:label="@string/app_name"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
            <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:mimeType="text/xml"
                    android:pathPattern=".*.war" />
                <data
                    android:mimeType="application/xml"
                    android:pathPattern=".*.war" />
                <data
                    android:mimeType="application/octet-stream"
                    android:pathPattern=".*.war" />
            </intent-filter>
        </activity>
        <activity
            android:name="za.ac.sun.battlemanager.CreateCharacterActivity"
            android:label="@string/title_activity_create_character"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
        </activity>
        <activity
            android:name="za.ac.sun.battlemanager.CreateItemActivity"
            android:label="@string/title_activity_create_item"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
        </activity>
        <activity
            android:name="za.ac.sun.battlemanager.CreateTerrainActivity"
            android:label="@string/title_activity_create_terrain"
            android:parentActivityName="za.ac.sun.battlemanager.EditTerrainListActivity"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="za.ac.sun.battlemanager.CreateActivity" />
        </activity>
        <activity
            android:name="za.ac.sun.battlemanager.CreateZoneActivity"
            android:label="@string/title_activity_create_zone"
            android:parentActivityName="za.ac.sun.battlemanager.CreateActivity"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="za.ac.sun.battlemanager.CreateActivity" />
        </activity>
        <activity
            android:name="za.ac.sun.battlemanager.EditCharacterListActivity"
            android:label="@string/title_activity_edit_character_list"
            android:parentActivityName="za.ac.sun.battlemanager.CreateActivity"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="za.ac.sun.battlemanager.CreateActivity" />
        </activity>
        <activity
            android:name="za.ac.sun.battlemanager.EditItemListActivity"
            android:label="@string/title_activity_edit_item_list"
            android:parentActivityName="za.ac.sun.battlemanager.CreateActivity"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="za.ac.sun.battlemanager.CreateActivity" />
        </activity>
        <activity
            android:name="za.ac.sun.battlemanager.EditTerrainListActivity"
            android:label="@string/title_activity_edit_terrain_list"
            android:parentActivityName="za.ac.sun.battlemanager.CreateActivity"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="za.ac.sun.battlemanager.CreateActivity" />
        </activity>
        <activity
            android:name="za.ac.sun.battlemanager.EditZoneListActivity"
            android:label="@string/title_activity_edit_zone_list"
            android:parentActivityName="za.ac.sun.battlemanager.CreateActivity"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="za.ac.sun.battlemanager.CreateActivity" />
        </activity>
        <activity
            android:name="za.ac.sun.battlemanager.EditPowerListActivity"
            android:label="@string/title_activity_edit_effect_list"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
        </activity>
        <activity
            android:name="za.ac.sun.battlemanager.CreatePowerActivity"
            android:label="@string/title_activity_create_effect"
            android:parentActivityName="za.ac.sun.battlemanager.EditPowerListActivity"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="za.ac.sun.battlemanager.EditEffectListActivity" />
        </activity>
        <activity
            android:name="za.ac.sun.battlemanager.EditConditionListActivity"
            android:label="@string/title_activity_edit_condition_list"
            android:parentActivityName="za.ac.sun.battlemanager.CreateActivity"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="za.ac.sun.battlemanager.CreateActivity" />
        </activity>
        <activity
            android:name="za.ac.sun.battlemanager.CreateConditionActivity"
            android:label="@string/title_activity_create_condition"
            android:parentActivityName="za.ac.sun.battlemanager.CreateActivity"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="za.ac.sun.battlemanager.CreateActivity" />
        </activity>
    </application>

</manifest>

1 个答案:

答案 0 :(得分:0)

如果我在同一android:mimeType标记中记得正确的一个android:pathPattern<data>。另外,<data>中只应有一个<intent-filter>。我的建议:分成六个单独的<intent-filter>

请注意,即使你这样做也存在我的问题How did intent-filter change from Android 2 to Android 4?