Android Question Registering custom file extensions

andyp

Member
Licensed User
Hi

I would like my app to open when the user clicks on a text file (email attachment) with a custom file extension (.cgh)

I have tried many solutions, all with the same issue - When I click on the .cgh file, I get the option to open it with my app. But having done that, my app now opens when I click on any file with an unknown file extension (say .arp)

Is there any way I can stop this behavior?

I would like my app to only open if the user clicks on a .cgh file.

Alternatively, is there any way to have my app come up as an option when I click on a .cgh file, but for this choice to not be remembered?

The relevant bit in my manifest is:

B4X:
AddActivityText(moreInfo,
        <intent-filter >
           <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
         <data android:mimeType="*/*" />
            <data android:pathPattern="*.cgh" />
        </intent-filter>
)

Thank you
Andrew
 

DonManfred

Expert
Licensed User
Longtime User
try it with
B4X:
<intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:scheme="file" />
    <data android:host="*" />
    <data android:pathPattern=".*\\.cgh" />
  </intent-filter>
 
Upvote 0

andyp

Member
Licensed User
Hi Don

Unfortunately that code does not work - the app does not come up as an option when I click on the .cgh file......
 
Upvote 0

andyp

Member
Licensed User
Tried as you suggested. Unfortunately that code does not work - the app does not come up as an option when I click on the .cgh file...…

B4X:
AddActivityText(moreInfo,
    <intent-filter >
       <action android:name="android.intent.action.VIEW" />
       <category android:name="android.intent.category.DEFAULT" />
       <data android:scheme="file" />
       <data android:host="*" />
       <data android:mimeType="*/*" />
       <data android:pathPattern="*.cgh" />
    </intent-filter>
)
 
Upvote 0

andyp

Member
Licensed User
Are there any other options?

Behavior with other ‘commercial’ applications (pdf files, etc) seems to work with no issues

Failing this, what is the best way of importing a text file of data (arriving in an email) into an app? Maybe save the file on the device, and I guess there is some way of opening a file from within an app using b4a?

Thank you for any thoughts...…..
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Behavior with other ‘commercial’ applications (pdf files, etc) seems to work with no issues
The intent filters are created based on the mime type. The file browser knows the mime type based on known extensions.

You can use ContentChooser to let the user choose a file or other resources.
 
Upvote 0

andyp

Member
Licensed User
Thank you. ContentChooser is working well.

But I hope Google 'fixes' Intents from the manifest file - I cants imagine the previously working Intent method of file association has been changed 'on purpose'.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…