0

I need to make an App able to open a specific file extension related to a custom file format, so that when I click on a file that has such extension It's shown the dialog with my App as one of the App that can open such file.

In past versions of Android I have achieved this adding the following Intent Filter in the manifest in the section of the MainActivity

<intent-filter android:icon="your_drawable-resource"
               android:label="your_string_resource"
               android:priority="integer"> 
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:scheme="file" />
    <data android:host="*" />
    <data android:pathPattern=".*\\.MY_CUSTOM_FILE_EXTENSION" />
</intent-filter>

That is analogous to the answer found in an old similar question.

Recently I have tried to do the same but this doesn't work anymore and my app doesn't appear registered as able to open that extension.

What is the proper way to register the App for a file extension now?

EDIT It's not a duplicate since I have clearly stated that method used previously by myself and in others similar questions doesn't work anymore and It has nothing to do with email attachment since It's related to an App that must be registered for Its own file format, not a common file format.

AndreaF
  • 11,975
  • 27
  • 102
  • 168
  • In which FIle browser you are checking this? – Swayangjit Oct 21 '19 at 13:38
  • @CommonsWare I's not a duplicate since I have clearly stated that method used previously by myself and in others similar questions doesn't work anymore and It has nothing to do with email attachment since It's related to an App that must be registered for Its own file format. – AndreaF Oct 21 '19 at 14:11
  • @Swayangjit in the default file browser – AndreaF Oct 21 '19 at 14:23
  • @CommonsWare What you mean exactly with ban of URI value? Bassically I need to register the App to open an undefined file and filter according pattern and scheme. (for this purpose would be useful to have a list of all supported `android:scheme` values but I haven't found It in documentation – AndreaF Oct 21 '19 at 21:50
  • "What you mean exactly with ban of URI value?" -- an app using the `file` scheme for their `ACTION_VIEW` `Intent` [results in a `FileUriExposedException` on Android 7.0+](https://stackoverflow.com/q/38200282/115145). Your app is expecting such a `Uri`, and few apps will use one on Android 7.0+. "Bassically I need to register the App to open an undefined file and filter according pattern and scheme" -- that is only practical for the `file` scheme, and few apps use it. – CommonsWare Oct 21 '19 at 22:07
  • @CommonsWare Even if I use `` in addition to `` wildcarding mimeTypes with ``the app isn't shown as able to open the file. Using the wildcard for all mime types in theory App should be register to support all formats. Why this doesn't happen? – AndreaF Oct 21 '19 at 22:34
  • If you have the `android:pathPattern` on that same ``, it is unlikely to match, as a `content` `Uri` can have any structure, not necessarily one with a file extension (let alone your file extension). If you add a parallel `` to the one in the question, with just `` and ``, your app should show up, albeit for any sort of file. – CommonsWare Oct 21 '19 at 22:37
  • @CommonsWare This aspect I haven't clear. Uri can have any structure, not necessarily one with a file extension, perfect, but since I have wildcarded path to be `whateverthing.MYEXTENSION` why this doesn't work to open a file that has MYEXTENSION? – AndreaF Oct 21 '19 at 22:54
  • The URL to this Web page has no file extension. That's fairly typical with Web URLs, and it is fairly typical with `content` `Uri` values as well. You are assuming that every `Uri` has a file extension, which is not the case. So, the `Uri` that the client app uses with `ACTION_VIEW` could be: `content://some.authority/this/bears/no/resemblance/2/anything`, and that will not match your wildcard pattern. Yet it might be a perfectly valid `Uri`, that one could use with a `ContentResolver` and `openInputStream()` to read in the content. – CommonsWare Oct 21 '19 at 23:04
  • @CommonsWare thanks for the help. The way android manages files and Uri is cumbersome and create useless annoyances. I don't see any valid reason to make an OS generating weird Uri without any standardized filepath form. To me this is a very bad design choice. – AndreaF Oct 21 '19 at 23:29

0 Answers0