1

I have been searching for a while and found out that I could use data providers using Intent Filters to enable my app to open up a custom file extension when I try to open the file in apps like File Managers and Whatsapp. But the funny thing is that it works only when I use a File picker on my MIUI device but my app doesn't show in the list when I click to open it from Whatsapp or my in-built File manager. This is my code below, exactly everything I have tried since:

  <activity
     android:label="@string/app_name"
     android:name=".exports.ImportActivity"
     android:configChanges="orientation|keyboardHidden"
     android:exported="true"
     android:screenOrientation="portrait"
     android:theme="@style/AppTheme.SlideVertical_recipient"
     android:windowSoftInputMode="adjustResize">
     <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:scheme="file" />
        <data android:scheme="content" />
        <data android:host="*" />
        <data android:pathPattern=".*\\.tmly" />
        <data android:mimeType="*/*" />
     </intent-filter>
  </activity>

Edit: The code still works even without <data android:scheme="content" />. I was just trying out everything I could find on ther Internet

Noah
  • 567
  • 5
  • 21
  • I guess whatsapp uses a non-standard way to open files, to be honest I don’t know how to open application chooser via whatsapp. – khoben Feb 17 '22 at 15:20
  • The application chooser opens up when you click on a file that was received or sent. In my case, it was a file with a .tmly extension that I am using in my app. – Noah Feb 17 '22 at 15:22
  • What your `` does is support very specific `Uri` values, ones that are not used all the time. In particular, relatively few `content` `Uri` values will have a file extension, just like many HTTP(S) URLs do not contain a file extension. – CommonsWare Feb 19 '22 at 16:23
  • @CommonsWare sir, could you explain further, I don't think I understand what you meant by *content Uri values* – Noah Feb 19 '22 at 16:55
  • Your `` has ``. This says "I want this filter to match an `Intent` that has a `Uri` whose scheme is `content`". That will be a `Uri` whose string representation starts with `content://`. – CommonsWare Feb 19 '22 at 17:13
  • Ok, I now understand what you meant. So what should I be using to make my app support file with **.tmly** extension? I am trying to implement export and import data feature in my app. – Noah Feb 19 '22 at 17:20
  • Have you tried with only the scheme=file, with no scheme=content? And without mime type. Related with clear info regarding this: https://stackoverflow.com/questions/1733195/android-intent-filter-for-a-particular-file-extension Especially 2nd answer. – Mattias Isegran Bergander Feb 23 '22 at 19:56
  • @MattiasIsegranBergander I did what you said, but still doesn't work. When I removed the mime type, it doesn't show up even on my file manager. – Noah Feb 25 '22 at 09:55

0 Answers0