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

前端 未结 4 679
花落未央
花落未央 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条回答
  •  爱一瞬间的悲伤
    2020-12-31 20:47

    You should not be overwriting other applications files. That said you have two solutions

    1. Use public external storage (like the SD card) to share the file between the apps.
    2. If the other app is not yours then you can't write to its /data directory, without root that is. Anything is possible with root, just don't expect your users to all have root access.

    Edit: Developer owns both applications

    Thanks for Roman Kurik for pointing this out. A link to his post on SO

    From the android docs

    android:sharedUserId

    The name of a Linux user ID that will be shared with other applications. By default, Android assigns each application its own unique user ID. However, if this attribute is set to the same value for two or more applications, they will all share the same ID — provided that they are also signed by the same certificate. Application with the same user ID can access each other's data and, if desired, run in the same process.

    So this is exactly the way user id's work in linux, essentially you are the owner of both and have read/write access to both.

提交回复
热议问题