android logging sdcard
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 sdcardwhereas 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-6C29Directory 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 freeI 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 EclipseI 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?
well - I did get it to work (i.e. canWrite returns true).
Here is what I did
- created a new SD card Image file using the following command
C:\android-scripts>mksdcard -l Emu1GSD 1024M C:\android-dev\emu_sdcard\emu1gsd.img
With the previous SD card image no label was used, the size was 8MB and the extension was not .img. I haven't bothered to find out which one of these is the likely reason. Also the previous image file may have been corrupt!
- the second step was to recreate a new AVD with the new SD Card Image file. Here is what the AVD looks like now
The getTotalspace issue as was mentioned in the previous comment still exists - I will create a new question for that.
Here is the message in the console window which I missed all the while -
[2010-12-28 12:14:08 - Emulator] ### WARNING: SD Card files must be at least 9MB, ignoring 'C:\android-dev\emu_sdcard\emu_logFile'
And the other moral of the story is - monitor the console Window too not just the LogCat window
精彩评论