Reputation: 1279
An application makes a file in data/data/package.name/file.txt
. Is there a way for me to open that file from another application (with different package)?
I tried reading the file the standard way (FileInputStream
), but I get EACCES error (no permission)
.
Can I maybe copy the file (withouth opening it) to root directory and then open it?
EDIT: What about changing permission of the file withouth root access?
Upvotes: 0
Views: 113
Reputation: 20406
By default, every Android application is able to access the files belonging to its own package only. This means your applications can only read files underneath the package with your package.name. If you try to read other files, you will get an access denied exception. This is Android's security model.
One exception is when another application stored its files using MODE_WORLD_READABLE or MODE_WORLD_WRITABLE flags, then every other application will be able to access (read or read & write) them. This option is deprecated in API level 17 and higher though.
Upvotes: 1
Reputation: 587
Your code is probably correct, you just need to add an extra /
(or File.separator
) before the file name as follows:
//Set desired file path. For example:-
File newxmlfile = new File(Environment.getExternalStorageDirectory() + "/new.xml");
try {
//Read file
} catch (Exception e) {
Log.e("IOException", "exception while reading file",
e);
}
Also the other applications must have set its data as readable with the appropriate permission.
Upvotes: 0