TC75 Android 4.4.2 : Problem with writing file on sd card

// Expert user has replied.
R Ram Charan 3 years ago
40 2 0

Hi,
 
I'm trying to write on removable storage , But getting IOException
 
java.io.FileNotFoundException: /storage/extSdCard/PWC/Images/IMG_20151210_113150.jpg: open failed: EACCES (Permission denied)
at libcore.io.IoBridge.open(IoBridge.java:409)
 
Caused by: libcore.io.ErrnoException: open failed: EACCES (Permission denied)
at libcore.io.Posix.open(Native Method)
at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110)
at libcore.io.IoBridge.open(IoBridge.java:393)
 
The line I used to write is
 
try{
 
FileInputStream myinput = new FileInputStream(from);
 
String outfilename = to;
 
OutputStream myoutput = new FileOutputStream(outfilename);
// transfer byte to inputfile to outputfile
byte[] buffer = new byte[1024];
int length;
while ((length = myinput.read(buffer)) > 0) {
myoutput.write(buffer, 0, length);
}
 
//Close the streams
myoutput.flush();
myoutput.close();
myinput.close();
 
return true;
}
catch ( IOException e){
e.printStackTrace();
return false;
}
 
from and to is a valid file location.
 
If I use Internal and Emulated External file path , Above is working fine.
If I use secondary or removable storage file path , getting issue.
 
The path gives canWrite as true.
 
Testing on Android 4.4.2 Samsung SM-G350E and Zebra TC75
 
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri); // set the image file namestartActivityForResult(intent, 300);
 
Using the above code is working and writing the image on samsung,
but failed to write on zebra , the save button with 'tick' icon has no response.

Please register or login to post a reply

2 Replies

R Ram Charan

My Bad ,

I had to use getExternalFilesDirs() to get array of all the files directory , which includes sdcard

Thanks ​

P Pietro Francesco Maggi

Hi Ram,
you can't write on the secondary storage, on a KitKat device (Android v4.4.x) outside of your own package folder (//data/Android/.
This is a change driven by Google in the Android 4.4 Compatibility Definition Document (CDD).​

Because on the TC75 you've an internal 1GB partition available as storage, the SDCard you put into the device is a "Secondary Storage" and you can write only in your own package folder.

I don't know why you're getting a different result on the Samsung device. Maybe because you don't have an internal partition available as storage or because Samsung is mounting the external SDCard as the primary storage.

In this case the solution would be to write in the internal partition or write on the SDCard in your own package folder.

~Pietro

CONTACT
Can’t find what you’re looking for?