0

Problem: I cannot get file extension specific intents to work suggested? I know this has been asked a lot on this forum but I'm not getting suggestions to work. I wondered if it was my Java Intent in Android.

What I've tried: I've used a few links on the forum, and the two below have about 30 answers between them, so I tried some of them. I'haven't found the correct combination apparently.

Android intent filter for a particular file extension?

Android intent filter: associate app with file extension

I've tried combinations to the point of copy/pasting the example and replacing the file extension. I've gotten it two ignore files, but it also ignores my expected extension (.db). I've tried other extensions like xml, jpg but still get the same result. I think it may be my java called Intent but don't know. It is a database file (xml), so maybe that poses a caveat. That's why I thought I would try posting here.

Android Manifest:

<activity android:name=".MainActivityMaster"
          android:launchMode="singleTop"
          android:theme="@style/Theme.AppCompat.NoActionBar"
          android:screenOrientation="portrait">
    <intent-filter>
        <action android:name="android.intent.action.MAIN"/>
        <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=".*\\.db" />

        <category android:name="android.intent.category.LAUNCHER"/>
    </intent-filter>
</activity>

Java Intent:

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("application/db");
resultLauncher.launch(intent);

Result:

svstackoverflow
  • 665
  • 6
  • 19
  • Your `Intent` and your `` are unrelated -- your `` is declaring that you have an `Activity` that supports `ACTION_VIEW`, and your `Intent` is for `ACTION_GET_CONTENT`. Also, `application/db` is not an official MIME type, so few if any devices will honor it. Overall, file extensions have never been well-supported in Android, and neither `ACTION_GET_CONTENT` nor newer replacements (e.g., `ACTION_OPEN_DOCUMENT`) will do anything with respect to file extensions. – CommonsWare Jan 03 '22 at 16:27
  • (er, sorry, that last sentence should read "will not do anything with respect to file extensions") – CommonsWare Jan 03 '22 at 16:45
  • @CommonsWare - Thanks for the input. That probably is the case then. I think I did see a post on a custom extension `Intent` but as you said... "never been well-supported." I just used an `.endsWith(".db")` on the string name to help. – svstackoverflow Jan 03 '22 at 18:36

1 Answers1

0

Based upon CommonsWare comment and the supporting link here, I decided to create a string .endsWith(".db") check as a workaround; which involved a custom PopupDialog.class I created for my overall application - which is a work in progress.

popup

svstackoverflow
  • 665
  • 6
  • 19