问题
I am doing an application which access the SD/Media card to display its images. But when device is connected via USB I cant access the media card. If thats the case, I want to show a message to user asking him to disconnect device form computer.
- How can I programatically check that SDCard is accessible or not ?
- How can I check whether the device is connected to computer via USB?
Thanks.
回答1:
I am not sure about your second question about checking whether the device filesystem is mounted via USB on a computer, but as for the first question, to check the available filesystems, call FilesystemRegistry.listRoots(), which will return an Enumeration of String objects. If "SDCard/" is in the enumeration, then the SDCard is available.
Some devices can also store images on the device storage as well, which is distinct from the SDCard. In that case, check for "store/" as the filesystem root.
来源:https://stackoverflow.com/questions/9262740/check-blackberry-is-connected-via-usb