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
Developer
Posts: 28
Registered: ‎12-18-2008
My Device: Not Specified
Accepted Solution

Reading the files using BlackBerry device simulator..

In the device simulator if we take a photo using the camera option it shows that it is saved as a .jpg file.

Can I read such a file using FileConnection method? Is that file is real?  

Or do I have to use a real BlackBerry device to simulate it?

 

Bacause what I'm trying is to read such image stored in the device and attach to an email and send.

But it seems as if that file cannot be accessed though I give the path of it.

 

Eg:

FileConnection fconn = (FileConnection)Connector.open("file:///SDCard/BlackBerry/picture/IMG00017.jpg");

 

 

 

Can anyone give a solution for this?

Developer
Posts: 3,951
Registered: ‎07-15-2008
My Device: Not Specified

Re: Reading the files using BlackBerry device simulator..

Yes you can read the image. Just cross verify your path of image.

Use Search. "Accept Solution" If the problem is resolved.
Developer
Posts: 28
Registered: ‎12-18-2008
My Device: Not Specified

Reading the files using BlackBerry device simulator..

I tried in every way I could, but none of them worked eventhough the image path is also correct...

This is part of the code which causes problems i guess..

 

DataBuffer buffer = null; 
                    try {
                       
        FileConnection fconn = (FileConnection)Connector.open("file:///Device Memory/samples/pictures/Accelerate.png");
                        if(fconn.exists()){


                        input = fconn.openInputStream();
                        buffer = new DataBuffer();
                        byte[] temp = new byte[1024];
                       
                        for( ;; ) {
                            int bytesRead = input.read( temp );
                            if( bytesRead == -1 ) {
                            break;
                            }
                            buffer.write( temp, 0, bytesRead );
                            }
                            input.close();
                            fconn.close();
                                                      
                        }
                        else{
                            System.out.println("File doesnt exist");
                        }
                           
                    } catch (IOException e2) {
                        // TODO Auto-generated catch block
                        e2.printStackTrace();
                    }
                   
                                                          
                    SupportedAttachmentPart sap = new SupportedAttachmentPart(mp,"image/jpeg","file.jpg",buffer.getArray());

 

 

Now this throws a Null Pointer Exception. It seems like the buffer is null.. 

Can anyone help me to solve this issue?

BlackBerry Development Advisor
Posts: 15,211
Registered: ‎07-09-2008
My Device: BlackBerry Passport
My Carrier: Bell

Re: Reading the files using BlackBerry device simulator..

Third party applications are not able to read the sample media (images, sounds, etc...) that is preinstalled on a BlackBerry handheld.  You should be able to to read files created by the user or by other applications.
Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Developer
Posts: 28
Registered: ‎12-18-2008
My Device: Not Specified

Re: Reading the files using BlackBerry device simulator..

Thanks Mark..

So if I take a photo using the simulator I should be able to read from where it is saved .. Is that so?

Since I'm using the simulator will there be any difference from reading from the real BB device?

Can I know whether there are any limitaions in the simulator which do not exist in the real device?

 

regards..

Highlighted
BlackBerry Development Advisor
Posts: 15,211
Registered: ‎07-09-2008
My Device: BlackBerry Passport
My Carrier: Bell

Re: Reading the files using BlackBerry device simulator..

Yes, you can access photos the user has take as well as any files they have stored on their BlackBerry handheld or micro SD card.

 

You can use a FileConnection in the BlackBerry Simulator.  The following link explains how to configure a micro SD card.

 

How To - Use a computer file system as a microSD card
Article Number: DB-00654

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800792/801083/How_To_...

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker