Android Question Set App as android default open with

Davisbc

Member
Licensed User
Does anyone know of code example to allow my all to be included in an OpenWith?

For example, i would like the app to show up for opening file with extension of .json of .geojson or whatever (but always text), for example; and receive the file for processing.

It seems like this is a common requirement.

Thanks in advance,
B
 

jkhazraji

Active Member
Licensed User
Longtime User
Does anyone know of code example to allow my all to be included in an OpenWith?

For example, i would like the app to show up for opening file with extension of .json of .geojson or whatever (but always text), for example; and receive the file for processing.

It seems like this is a common requirement.

Thanks in advance,
B
You need to use Android's Intent Filter system to register it as a handler for specific file types. This is done by declaring an <intent-filter> inside your app's manifest.
Here is a sample:
XML:
AddActivityText(Main,
       <intent-filter>
           <action android:name="android.intent.action.VIEW" />
           <category android:name="android.intent.category.DEFAULT" />
             <category android:name="android.intent.category.OPENABLE" />
           <data android:mimeType="application/json" />
       </intent-filter>
       )
Use contentChooser to pick your file. You need to adddPermission (PERMISSION_READ_EXTERNAL_STORAGE)
 
Upvote 0
Top