Android - Открытие вложения Gmail с моим приложением

Мне нужно открыть файлы с пользовательским расширением, используя мое приложение. Я могу сделать это с помощью фильтров Intent, когда файл находится на моей SD-карте. Я также могу просмотреть кнопки "скачать" и "предварительный просмотр", если файл отправлен в виде вложения Gmail. Однако, когда я нажал на кнопку загрузки / предварительного просмотра, я получил сообщение - "Извините, вложение не может быть загружено".

Я думал, что это проблема с моим приложением. Но у меня возникла случайная идея, и я установил приложение "Скачать все файлы" на свой телефон. https://play.google.com/store/apps/details?id=com.hwkrbbt.downloadall&hl=en Затем, когда я нажимаю кнопку загрузки в Gmail, для загрузки файла предлагается загрузить и все файлы, и мое приложение. Я выбрал свое приложение, и все работает отлично!

Это какая-то проблема безопасности? Это мои намеренные фильтры:

<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="*/*" />
         <data android:scheme="content" android:host="*"
            android:pathPattern=".*\\.ate" />
        <data android:scheme="file" android:host="*"
            android:pathPattern=".*\\.ate" />
    </intent-filter>
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <data android:mimeType="application/*" host="*" android:pathPattern=".*.ate" android:scheme="content" />
    </intent-filter>

РЕДАКТИРОВАТЬ: Вот полный тег активности.

  <activity android:name=".TestApp"
              android:label="@string/app_name" 
              android:configChanges="orientation|keyboardHidden"
              android:launchMode="singleTask">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <intent-filter>
            <action android:name="com.TestApp.TestApp.NOTIFICATION" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
        <!-- Opening .ate file start -->
        <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=".*\\.ate" />
          </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:mimeType="*/*" />
         <data android:scheme="content" android:host="*"
            android:pathPattern=".*\\.ate" />
        <data android:scheme="file" android:host="*"
            android:pathPattern=".*\\.ate" />
    </intent-filter>
    <intent-filter>
        <action android:name="android.intent.action.VIEW"/>
        <category android:name="android.intent.category.BROWSABLE"/>
        <category android:name="android.intent.category.DEFAULT"/>
        <data android:scheme="file" android:pathPattern=".*\\.ate" android:mimeType="application/octet-stream"/>
        <data android:scheme="content" android:pathPattern=".*\\.ate" android:mimeType="application/octet-stream"/>
        </intent-filter>
        <!-- Opening .ate file end  -->
    </activity>

1 ответ

Я понял это сам, поэтому выкладываю решение, на случай, если кто-то еще столкнется с этой странной проблемой.

Фильтр намерений требует как содержимого, так и типов файловых схем, с помощью mimetype application/octetstream

<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:scheme="file" android:pathPattern=".*\\.inform" android:mimeType="application/octet-stream"/>
<data android:scheme="content" android:pathPattern=".*\\.inform" android:mimeType="application/octet-stream"/>

Другие вопросы по тегам