Access to MODE_WORLD_READABLE files in application

2019-08-13 09:08发布

问题:

We have built an Android application which is used to collect data (for volleyball stats). This application creates a data file which we ultimately want to be transferred to desktop computers (Windows PCs and Macintoshes).

We currently write the data out as a simple character stream in the default application directory (data/data/appname/files) and specify MODE_WORLD_READABLE when we create each of these data files.

The problem is that even though the data files are MODE_WORLD_READABLE, the various utilities which we would like to use to transfer the data cannot see the data files. I assume that the problem is that they may have read access to the files, but they do not have read access to the directories in which the files are stored. Specifically, I am unable to browse to the files using the ES File Explorer app on the Android device and I am unable to browse to the files when I connect my Android device to the PC or Macintosh as a USB device.

Is my only solution to write files to the external directories, or is there something I am missing here about using MODE_WORLD_READABLE with application directories?

回答1:

The file access mode for the application base directory (usually something like /data/data/com.package.app) and the top directories in it (databases, files, cache, ...) is rwxrwx--x. For other users than the application itself the relevant part is --x, which mean the directories can not be read (browsed) but they can be traversed. So you can read MODE_WORLD_READABLE files if you know exactly what you are looking for (the complete path).



回答2:

We currently write the data out as a simple character stream in the default application directory (data/data/appname/files) and specify MODE_WORLD_READABLE when we create each of these data files.

AFAIK you cant access files from application sandbox (i.e /data/data/appname/files).If it were possible then you may never have used Content Providers.

The only solution i see here is whatever you want to achieve is only possible on Rooted Devices