10-19-2012 02:56 AM
I am new to Blackberry development. In my application i want to download and save files to SDCARD from remote url.
But whn i connected my device to desktop as USB drive. It says SDCARD is not found.
Is there any way to save files to SDCARD whn USB port is opened?
10-19-2012 04:11 AM
10-19-2012 04:19 AM
Thanks for you reply. If not possible means i need to alert the user to Disconnect the USB drive. For that i need to identify whether USB port is open or not.
i tried the following code .
private void checkFilesystem() {
boolean usbConnected = false;
boolean massStorageEnabled = false;
boolean sdcardPresent = false;
int state = USBPort.getConnectionState();
if ( ( SystemListener2.USB_STATE_ENUMERATED & state ) == state ) {
usbConnected = true;
if ( ( SystemListener2.USB_STATE_MS_INTERFACE_ENUMERATED & state ) == state ) {
massStorageEnabled = true;
}
}
Enumeration roots = FileSystemRegistry.listRoots();
while (roots.hasMoreElements()) {
String root = (String) roots.nextElement();
System.out.println( "Found Root: " + root );
if ( root.equals( "SDCard/" ) ) {
sdcardPresent = true;
}
}
System.out.println( "USB: " + ( usbConnected ? "" : "NOT " ) + "CONNECTED" );
System.out.println( "Mass Storage Mode: " + ( massStorageEnabled ? "ENABLED" : "DISABLED" ) );
System.out.println( "SDCard: " + ( sdcardPresent ? "" : "NOT " ) + "FOUND" );
}
But it always shows "USB NOT CONNECTED" even though my device is connected with my desktop as USB DRIVE.
If you have any other sample please share it.
10-19-2012 04:39 PM
You can try this routine that I have used before for this issue :
public static int isStoreAvailable()
{
int avail = -1;
Enumeration drives = FileSystemRegistry.listRoots();
while(drives.hasMoreElements())
{
String root = (String) drives.nextElement();
System.out.print("Supported File System Root = " + root);
if(root.equalsIgnoreCase("store/"))
{
avail = 1;
break;
}
else
{
avail = -1;
}
}
if(USBPort.getConnectionState() == 3 || USBPort.getConnectionState() == 19)
{
avail = 2;
}
return avail;
}
10-20-2012 04:09 PM
Hi raj,
You have no need to make any condition, just remove safely the device from your system and let it connect via USB. This will enable access to SD card.
Otherwise you can use the following code for checking availability of SD card:
String root = null;
Enumeration e = FileSystemRegistry.listRoots();
while (e.hasMoreElements()) {
root = (String) e.nextElement();
if (root.equalsIgnoreCase("sdcard/")) {
// device has microSD inserted
return true;
}
}
return false;
You can check the availability of SD card before any operation..