3

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?

Mark Manickaraj
  • 1,541
  • 5
  • 26
  • 43

1 Answers1

5

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.

Community
  • 1
  • 1
Bob
  • 1,151
  • 1
  • 12
  • 26
  • Hi bob, thank's for the input. Sorry but what do you mean by place it in activity/service/receiver? – Mark Manickaraj Sep 22 '11 at 19:28
  • Oh I was just referring to the location in the Android Manifest file. Sorry, when I wrote the response I was kinda drowsy so I didn't notice how unclear my "clarifaction" was. :D http://developer.android.com/guide/topics/manifest/manifest-intro.html Thats the page that'll tell you where to put things in the manifest file – Bob Sep 22 '11 at 23:23
  • 2
    I'm having problems implementing this. If I paste this code in my main activity tags of the manifest and change it to my custom extension, then use root explorer to go to a file with that custom extension... CLicking on it doesn't do anything... thoughts? – Nick Feb 24 '12 at 17:55