Search code examples
androidunity-game-enginefile-permissionspermission-deniedfile-sharing

sharing files using MODE_WORLD_READABLE on Android/Unity


i will start to explain my problem and then i do the question.

Problem

I am trying to share a file between two different android apps. The application A and the application B. Both made using Unity.

The application A save on internal storage a file(PUBLIC_FILE) using the MODE_WORLD_READABLE. Later the application B try to access to PUBLIC_FILE but permission to access is denied. I can´t understand why.

Device used: Nexus 7
Android Version: 5.1

Terminal Emulator

Using the Terminal Emulator, i verified that the permissions of the PUBLIC_FILE are: -rw-rw-r-- . So all users/apps should have permission to read.

I verified also that on terminal emulator i was able to read the PUBLIC_FILE.

Question

Why i can read the PUBLIC_FILE using the terminal emulator but i can´t read the PUBLIC_FILE using the application B?

if you need some more information/explanation just ask. :)


Solution

  • So i could not solve this exact problem.

    But i found other solution (to share a file between 2 different apps). I used the external storage instead of the internal storage.

    • I gived the permission WRITE_EXTERNAL_STORAGE to application A.
    • I gived the permission READ_EXTERNAL_STORAGE to application B.
    • I saved the file (using application A) on the external folder of A.
    • I loaded the file (using application B) from the external folder of A.
      • To get the external folder i use the method [getExternalFilesDir] and then i use a string method to replace the package name of application B for the package name of application A.