Sharing files between android apps? -
can suggest how can share file between n number of android applications? suggest me links, code etc? in advance !!
look @ android.support.v4.content.fileprovider. component can share file 1 app other apps in system means of content uri, allows hosting app use uri (not file) permissions control file. means hosting app can set temporary access permissions instead of permanently changing file's permissions. there's no performance penalty, every time app needs file can content uri , temporary permissions. secure.
fileprovider subclass of contentprovider, , works in same way.
the current reference doc bit vague. i'll try summarize:
hosting app needs declare provider in manifest:
<provider android:name="android.support.v4.content.fileprovider" android:authorities=authority android:exported="false" android:granturipermissions="true"> <meta-data> android:name="android.support.file_provider_paths" android:resource="@xml/some_name" /> </provider>
- "authority" uri authority make up.
- some_name name of xml file put in project (usually in
xml/
subdirectory.
the contents of some_name.xml
is
<paths> <files-path name="path-segment" path="filepath"/> ... </paths
files-path
shares files in private file area (value returned context.getfilesdir()), can share files in external area , cache area.
filepath
is subdirectory in private file area, example images/
. path-segment
corresponding path goes content uri. example, if use authority of
com.example.myapp.fileprovider
and put in
<files-path name="images" path="images/">
then resulting content uri starts with
content://com.example.myapp.fileprovider/images
if want share out file images/myimage.jpg, resulting content uri is
content://com.example.myapp.fileprovider/images/myimage.jpg
the hosting app generates content uri calling `fileprovider.geturiforfile()
what's nice don't have implement subclass of fileprovider in code; it's default behavior sufficient people's needs.
see javadoc more info.
Comments
Post a Comment