How to transfer files between Android applications running on the same device?

前端 未结 3 1954
遇见更好的自我
遇见更好的自我 2021-01-31 17:50

I am writing an Android application that interfaces with a RESTful service. This web service essentially fronts a file system, and provides metadata as well CRUD access to the

3条回答
  •  庸人自扰
    2021-01-31 18:33

    Using the SD card is definitely the recommended way to go to share files on Android.

    However, I would go with a modified hybrid solution which makes use of startActivityForResult() and onActivityResult() (docs here) on the client side to communicate CRUD requests (and getting the Uri to the file(s) on the SD card if needed) if you don't mind creating a dummy activity as a front end to your service. Clients, once finished with the file(s), can call startActivityForResult() again to alert your app to changes.

    Of course this can be done with startService()/bindService() however it doesn't provide an easy way for clients to obtain a status result especially if you need IPC.

    Although content providers/resolvers feel like the correct way to go about things, I do feel it is more for single direction requests specific to providing/consuming content.

提交回复
热议问题