Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Contributor
raj_eemtec
Posts: 10
Registered: ‎09-18-2012
My Device: 9650
My Carrier: Airtel

Save Files on SDCARD

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?

Please use plain text.
Developer
simon_hain
Posts: 15,940
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: Save Files on SDCARD

no, if you mount the SD card on the PC via USB it has exclusive access to it and the device won't be able to access it.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Contributor
raj_eemtec
Posts: 10
Registered: ‎09-18-2012
My Device: 9650
My Carrier: Airtel

Re: Save Files on SDCARD

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.

Please use plain text.
Developer
StevenKader
Posts: 635
Registered: ‎02-03-2010
My Device: Z10 LE
My Carrier: Rogers

Re: Save Files on SDCARD

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;
    }

 


Steven Kader at JaredCo
   Follow me on Twitter    |     Mipixi.com :  Web App for Photo Sharing
Please use plain text.
Trusted Contributor
ankitagrawal
Posts: 141
Registered: ‎02-15-2012
My Device: 9800
My Carrier: Airtel

Re: Save Files on SDCARD

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..

Please use plain text.