Cannot Write On Micro SDCard On BlackBerry

2019-06-22 08:36发布

I am trying to save some files on micro SDCard. To check the availability of SDCard, I am using the following method;

private boolean isSdCardReady() {
    Enumeration e = FileSystemRegistry.listRoots();

    while (e.hasMoreElements()) {
        if (e.nextElement().toString().equalsIgnoreCase("sdcard/")) {    
            return true;
        }
    }
    return false;
}

Even if this method returns true, when I try to save files, it gives exception net.rim.device.api.io.file.FileIOException: File system is not ready.

What does this means? If SDCard is not available, then why its listed in FileSystemRegistry.listRoots()?

How can I make sure that SDCard is available for writing?

My development environment:

  • BlackBerry JDE Eclipse Plugin 1.5.0
  • BlackBerry OS 4.5
  • BlackBerry Bold with a 3G card

2条回答
爷的心禁止访问
2楼-- · 2019-06-22 09:26

Solved the problem. I was looking for "sdcard" while rootsEnum.nextElement().toString(); returns "SDCard". Yeah, its case sensitive. Now, instead of using hard-coded "SDCard", I've changed the above method to the following;

private static String getSdCardRootDir() {
    Enumeration rootsEnum = FileSystemRegistry.listRoots();

    while (rootsEnum.hasMoreElements()) {

        String rootDir = rootsEnum.nextElement().toString();

        if (rootDir.equalsIgnoreCase("sdcard/")) {
            return "file:///" + rootDir;
        }
    }

    return null;
}

Using this, I got the root directory in its system defined case.

查看更多
戒情不戒烟
3楼-- · 2019-06-22 09:32
  1. Usually I had this error when I tried to access SD card on device restart. You have to postpone all operations in app until startup finished:

    while (ApplicationManager.getApplicationManager().inStartup()) {
        try {
            Thread.sleep(500);
        } catch (InterruptedException ignored) {
        }
    }
    
  2. I remember one more possible cause mentioned here. You have to close all streams after using.

查看更多
登录 后发表回答