I need my app to be the default action for opening a particular file type. How do I control this? Also, how can my app access the file being opened?
Thanks.
I need my app to be the default action for opening a particular file type. How do I control this? Also, how can my app access the file being opened?
Thanks.
As far as I'm aware you can't enforce it upon the user to make YOUR application the default for opening a particular file extension. The user must choose to make your application the default. As for the second question I don't know but thought I'd provide a partial answer. :)
Have a look at android.content.Intent
.
An Intent provides a facility for performing late runtime binding between the code in different applications. Its most significant use is in the launching of activities, where it can be thought of as the glue between activities. It is basically a passive data structure holding an abstract description of an action to be performed. The primary pieces of information in an intent are:
action -- The general action to be performed, such as ACTION_VIEW, ACTION_EDIT, ACTION_MAIN, etc.
data -- The data to operate on, such as a person record in the contacts database, expressed as a Uri.
Your activity can obtain the Intent that launched it by calling Activity#getIntent()
and then use Intent#getData()
to determine the URL of the data to open.
Your manifest should specify that one of your activities can view a specific type of data using an <intent-filter>
element. If the user attempts to view this kind of data, the system will figure out which activity across all apps on the system should get to handle it.
If there is only one app capable of viewing the data it will be launched automatically. If more than one app can handle the intent, the user will be presented with a dialog asking which app they would like to use, along with a checkbox for making that choice the default for next time. Users can clear defaults from the systemwide Settings.
As Aidan noted there is no way to hijack the default. The user must choose to make your app default for handling that type of data.