开发者

android logging sdcard

开发者 https://www.devze.com 2023-01-31 21:55 出处:网络
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

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?


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

    android logging sdcard

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

0

精彩评论

暂无评论...
验证码 换一张
取 消