Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android custom file extension

I want my android app to be able to share files through bluetooth, e-mail, wifi direct etc... (the standard sharing methods). I want to parse my data into a file with a custom extension and send it through some sharing method say bluetooth. The recipient should be able to open the file then my app starts and handles the file. Searched around the internet and came up short, does anyone know any good sites with tutorials on this? Or perhaps any reading materials on this topic?

like image 370
Mark Manickaraj Avatar asked Dec 10 '25 14:12

Mark Manickaraj


1 Answers

Ha! I also initially seemed to come up dry on this search, but my persistence finally pulled through.

Android intent filter: associate app with file extension

So, what they did on here is set up a intent-filter in the manifest.xml file that will enable your app to open those kinds of files. In your case, I would suspect that your code would look something like this

<intent-filter android:icon="drawable resource"
               android:label="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=".*\\.CUSTOM_FILE_EXTENSION" />
</intent-filter>

I presume that the file browsers will be able to get the icon to display from that part of the intent code. But I don't know too much about that, so don't quote me on it :p

Edit: This intent filter should go inside the activity/service/receiver that is going to process the custom file the user is opening.

like image 136
Bob Avatar answered Dec 12 '25 02:12

Bob



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!