I sent to the emulated android device SD card using DDMS and I can even see these in DDMS. The file names are POS1.png
and POS2.png
. The sdcard path is /storage/sdcard/foldername
In my code I want to check if my file isFile() so i have written
String filepath = "/storage/sdcard/foldername/POS1.png";
File file = new File(filepath);
if (!file.isFile()){
//do something
}
else{
//do something else
}
The if condition is always returning true (i.e. file is not a file).
I think it may be a permission issue (the current permissions on the files are u=>rwx
, g=>rwx
) so I am trying to change the permission of the file from adb shell
:
C:\> adb shell
root@generic:/ # su
Output: su
root@generic:/ # chmod -R 777 /storage/sdcard/foldername/
Output: chmod -R 777 /storage/sdcard/foldername/
root@generic:/ # ls -l /storage/sdcard/foldername/
The permissions still show the same. Even in the DDMS they're the same. I even restarted the device and eclipse, no change. I tried the following variations too:
root@generic:/ # chmod -R 777 /storage/sdcard/foldername/*
root@generic:/ # chmod -R 777 /storage/sdcard/foldername/*.png
root@generic:/ # chmod 777 /storage/sdcard/foldername/POS1.png
Using u+rwx
/ g+rwx
/ o+rwx
/ a+rwx
in place of 777
gives me a "Bad Mode" message
Thank you in advance for the help!
Edit: So I used the following code to check the exception:
try {
FileInputStream fis = null;
fis = new FileInputStream("/storage/sdcard/foldername/POS1.png");
} catch (IOException e) {
Log.e("openfile", "Exception:"+e.getMessage());
}
I got the message open failed: EACCES (Permission Denied)"
ChuongPham's answer is correct, if a little dry.
So, to fix this problem you have to add the "Uses" permission to your manifest file (by default this should be "AndroidManifest.xml"), which, in XML, looks just like ChuongPham wrote, and should be inside the "manifest" tag, but not deeper (not in "application" or any other).
From Eclipse: