Write a private access file to another app's files directory

前端 未结 4 677
花落未央
花落未央 2020-12-31 19:57

The two apps have the same sharedUserId. When I use this code in app1

context.openFileOutput(\"/data/data/org.me.app2/files/shared-data.dat\", MODE_PRIVATE)
         


        
4条回答
  •  梦毁少年i
    2020-12-31 20:34

    Since this is months old I assume you've already solved your problem, but I'll contribute anyway.

    Sharing data between apps is what ContentProviders are for. Assuming that you know how to write a ContentProvider and access it, you can access files via ParcelFileDescriptor, which includes constants for the mode in which you create the files.

    What you need now is to limit access so that not everybody can read the files through the content provider, and you do that via android permissions. In the manifest of one your apps, the one that will host the files and the content provider, write something like this:

    
    

    and in both apps add this:

     
    

    by using protectionLevel="signature", only apps signed by you can access your content provider, and thus your files.

提交回复
热议问题