1

I have read a couple of similar questions (Android intent filter for a particular file extension?, Creating app which opens a custom file extension, Associating App with Epub format), but my question is slightly different. Sorry for the long post with pictures, but it would be better to see what I mean.

I want to open custom file type from applications like File explorer. My intent filter looks like:

[IntentFilter(new[] { Intent.ActionView, Intent.ActionSend, Intent.ActionEdit },
                    Categories = new[] { Intent.CategoryDefault },
                    DataMimeType = "*/*",
                    DataHost = "*",
                    DataPathPattern = ".*\\.pdo",
                    Icon = "@drawable/icon"
    )]

When I tap on the file in Total Commander, the next popup window appeared:

enter image description here

I could select "Open with" or "Open as", and in the succeeding window select my app. All is OK.

But when I tap on the file in File explorer (Samsung A51), the next popup window appeared:

enter image description here

So the first question is what I missed and how to tell File Explorer to open this file with my app.

And when I tap on the txt-file, the next window appeared:

enter image description here

It would be the better option for my app to be shown in this nice window :) So the 2nd question is how to achieve this behavior. Thank you in advance.

Edit

Here is a relevant part of generated AndroidManifest.xml

  <manifest>
    <application
          android:name="android.app.Application"
          android:debuggable="true"
          android:appComponentFactory="androidx.core.app.CoreComponentFactory"
          android:requestLegacyExternalStorage="true">
      <activity
            android:theme="@2131689703"
            android:icon="@2131165558"
            android:name="MainActivity"
            android:launchMode="2"
            android:configChanges="0x26c0"
            android:alwaysRetainTaskState="true">
        <intent-filter android:icon="@2131165558">
          <action android:name="android.intent.action.VIEW" />
          <action android:name="android.intent.action.SEND" />
          <action android:name="android.intent.action.EDIT" />
          <category android:name="android.intent.category.DEFAULT" />
          <data android:host="*" />
          <data android:pathPattern=".*.pdo" />
          <data android:mimeType="application/pdo" />
          <data android:mimeType="application/octet-stream" />
        </intent-filter>
      </activity>
      <activity
            android:theme="@2131689957"
            android:icon="@2131165558"
            android:name="SplashActivity"
            android:configChanges="0x480"
            android:noHistory="true">
        <intent-filter>
          <action android:name="android.intent.action.MAIN" />
          <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
      </activity>
      <provider
            android:name="xamarin.essentials.fileProvider"
            android:exported="false"
            android:authorities="de.novel.loadsol.fileProvider"
            android:grantUriPermissions="true">
        <meta-data
              android:name="android.support.FILE_PROVIDER_PATHS"
              android:resource="@2131820550" />
      </provider>
    </application>
  </manifest>

Edit 2

It looks like problem is specific for some devices. On Vivo and Honor phones File explorer opens my app well.

Miamy
  • 2,162
  • 3
  • 15
  • 32

2 Answers2

1

After spending a whole day I figured out only one option which works for Samsung File Explorer. So I added one more intent filter:

  [IntentFilter(new[] { Intent.ActionView, Intent.ActionSend, Intent.ActionEdit, 
                        Intent.ActionGetContent, Intent.ActionSendto },
                    Categories = new[] { Intent.CategoryDefault, 
                                         Intent.CategoryBrowsable, Intent.CategoryOpenable },
                    Icon = "@drawable/icon",
                    DataMimeType = "*/*",
                    DataScheme = "content"
    )]

The main disadvantage of this approach is obvious - my app is suggested for opening any file from the explorer. I tried different mime types, such as application/octet-stream, application/binary, application/pdo, but all of them doesn't work. Of course, I'm checking a file type in the app and 'foreign' files will not be opened, but this issue is still annoying.

I'm still wondering why content is a single way to interact with some file explorers (I found this behavior in Samsung devices only, but this can happen with some other devices too, I guess).

Miamy
  • 2,162
  • 3
  • 15
  • 32
0

I wanted a similar behavior before for .smbf file extension in my app. These are the final settings that I had reached.

[IntentFilter(
    actions: new string[] { Intent.ActionView },
    Categories = new string[] { Intent.CategoryDefault, Intent.CategoryBrowsable },
    DataPathPatterns = new[] { @".*\\.smbf", @".*\\.smbf" },
    DataMimeTypes = new[] { "*/*", "*/*" },
    DataHosts = new[] { "*", "*" },
    DataSchemes = new[] { "content", "file" })]
momvart
  • 1,737
  • 1
  • 20
  • 32
  • Thank you, but this doesn't help. File explorer still doesn't suggest my app for file opening. – Miamy Apr 02 '21 at 08:33
  • @Miamy, I think you should play with filters to find what Samsung file explorer asks for, because any app may use its special filter. Also, you can check other app manifests which are working correctly with the file explorer. – momvart Apr 02 '21 at 09:49