Reputation: 391
For an existent file in the internal storage of the phone, path of which is /system/data/recf/pic.jpg, constructing inputStream using openInputStream() method throws FileNotFoundException.
This is what I am doing-
ContentResolver cr = context.getContentResolver();
InputStream inputStream = null;
Uri filename = Uri.parse("file:///system/data/recf/pic.jpg");
inputStream = cr.openInputStream(filename);
But it is throwing a FileNotFoundException. I have checked that the file exists. Stuck for a long time, please help. Thanks.
Upvotes: 2
Views: 3430
Reputation: 391
Device's Internal Storage (Phone Storage) is still considered External Storage in terms of Android. "External Storage" may refer to removable storage such as SD card or non-removable internal storage of phone.
"Internal Storage" refers to a private space of your app which is not shared with anyone, including the user.
Hence, permission to read from and write to External Storage was required. On Android M+, real-time permission was required.
Upvotes: 2
Reputation: 4678
I can see you are parsing a hard coded String for path
Uri filename = Uri.parse("file:///system/data/recf/pic.jpg");
and you are passing file with triple forward slashe. This may be the problem. First you need to make sure that the path is correct. You may use file object for this to verify in actually there is a file with provided path. You may use below code for checking.
File file = new File("Your path");
if(file.exists()) {
// if this is true that means file exists in actual then
//make uri and get the stream as you are already doing
}
Most probably this issue belongs to the path. Hope my answer helps you.
Upvotes: 1