android logging sdcard
- by Abhi Rao
Hello,
  With Android-Emulator I am not able to write/create a file on the SD Card (for logging).
 Here is what I have done so far
- Run mksdcard 8192K C:\android-dev\emu_sdcard\emu_logFile
- Create a new AVD, when assign emu_logFile to it so that when I view the AVD Details it says C:\android-dev\emu_sdcard\emu_logFile against the field "SD Card"
- Here is the relevant code  
public class ZLogger {   
  static PrintWriter zLogWriter = null;
private static void Initialize() {
    try {
        File sdDir = Environment.getExternalStorageDirectory();
        if (sdDir.canWrite()) {
            :
            File logFile = new File (sdDir, VERSION.RELEASE + "_" + ".log");
            FileWriter logFileWriter = new FileWriter(logFile);
            zLogWriter = new PrintWriter(logFileWriter);
            zLogWriter.write("\n\n - " + date + " - \n");               
        }
    } catch (IOException e) {
        Log.e("ZLogger", "Count not write to file: " + e.getMessage());
    }
}
sdDir.canWrite returns false - please note it not the exception
from adb shell when I do ls I see sdcard as link to /mnt/sdcard. When I do ls -l /mnt here is what I see  
ls -l /mnt
ls -l /mnt
drwxr-xr-x root     system            2010-12-24 03:41 asec
drwx------ root     root              2010-12-24 03:41 secure
d--------- system   system            2010-12-24 03:41 sdcard  
whereas if I go to the directory where I created emu_sdcard - I see a lock has been issued, as shown here  
C:dir android-dev\emu_sdcard
 Volume in drive C is Preload
 Volume Serial Number is A4F3-6C29  
Directory of C:\android-dev\emu_sdcard  
12/24/2010  03:41 AM                .
12/24/2010  03:41 AM              ..
12/24/2010  03:17 AM         8,388,608 emu_logFile
12/24/2010  03:41 AM              emu_logFile.lock
               1 File(s)      8,388,608 bytes
               3 Dir(s)  50,347,704,320 bytes free  
I have looked at these and other SO questions
Android Emulator sdcard push error: Read-only file system (2)
Not able to view SDCard folder in the FileExplorer of Android Eclipse  
I have added the following to AndroidManifest.xml
**uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"   **
Please let me know your thoughts - what am I missing here? Why does canWrite return false? What should I do to add permissions to sdcard?