Search code examples
androidandroid-intentfile-extension

Why can I not get suggested file specific extension intents to work?


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:


Solution

  • 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