在深入探讨问题之前,我先给您提纲。电子邮件(例如Gmail)上有一些文件(图像和pdf)。当用户点击某些MIME类型的文件(例如image / jpeg)时,我想将我的应用添加到应用选择器中。

这是我的清单。

<activity
        android:name="MyActivity"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
        android:label="@string/app_name"
        android:launchMode="singleTop"
        android:alwaysRetainTaskState="true"
        android:windowSoftInputMode="stateHidden">

        <intent-filter>
            <action android:name="android.intent.action.PICK"/>
            <category android:name="android.intent.category.DEFAULT"/>
            <data android:mimeType="image/jpeg"/>
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.GET_CONTENT" />
            <category android:name="android.intent.category.DEFAULT"/>
            <category android:name="android.intent.category.OPENABLE"/>
            <data android:mimeType="image/jpeg"/>
        </intent-filter>
        <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:host="*" android:mimeType="application/pdf" android:scheme="" android:pathPattern=".*/.pdf" />
            <data android:mimeType="application/pdf"/>
        </intent-filter>
 </activity>


我尝试了意图过滤器。尝试了三种不同的方式。没事。该应用程序未显示在应用程序选择器中。我缺少什么吗?
请分享您的想法!

最佳答案

尝试这个:

<activity
    android:name="MyActivity"
    android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
    android:label="@string/app_name"
    android:launchMode="singleTop"
    android:alwaysRetainTaskState="true"
    android:windowSoftInputMode="stateHidden">
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:scheme="file" />
            <data android:host="*" />
            <data android:pathPattern=".*\\.pdf" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:scheme="file" />
            <data android:host="*" />
            <data android:mimeType="image/jpeg" />
        </intent-filter>
</activity>

10-07 19:01
查看更多