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
Trusted Contributor
QuestionMan
Posts: 167
Registered: ‎06-30-2011
My Device: n/a
Accepted Solution

Can someone explain why this code isn't overwriting another file on the sd card?

I am using a bitmap array with a few different images. Depending on a trigger, I want to change the blackberry homescreen wallpaper to the image of my choice. I can do this for only 1 image, it is not updating when it should be. Here is my code, help!!!:

 

**note D.kF[] is a Bitmap array

**D.bgNumber is changing according to the program (ie, it should be a different image)

       

 

    Graphics graphics =Graphics.create(D.kF[D.bgNumber]);  

   
JPEGEncodedImage encoder =JPEGEncodedImage.encode(D.kF[D.bgNumber],100);  
   
try{  
       
ExtendedFileConnection fconn =(ExtendedFileConnection)Connector  
       
.open("file:///store/home/user/pictures/image.jpg",  
               
Connector.READ_WRITE);  
        fconn
.enableDRMForwardLock();  
       
if(!fconn.exists()){  
            fconn
.create();  
       
}  
       
OutputStream os = fconn.openOutputStream();  
        os
.write(encoder.getData());  
        os
.close();  
        fconn
.close();  
   
}catch(Exception e){  
       
System.out.println("Output file error: "+ e.getMessage());  
   
}  

   
HomeScreen.setBackgroundImage("file:///store/home/user/pictures/image.jpg");

Developer
Developer
CMY
Posts: 1,123
Registered: ‎02-10-2009
My Device: 8130 / 8350 / 9530 / 9550 / 9850 / PlayBook

Re: Can someone explain why this code isn't overwriting another file on the sd card?

Have you check ed to see if the file is being overwritten and the icon not updated or if the file is not being overwritten as well? Also, if you're wanting to overwrite the file i would call truncate after opening it just to make sure the read_write head is at the beginning of the file.
Developer
smiley
Posts: 1,497
Registered: ‎07-14-2008
My Device: Z10

Re: Can someone explain why this code isn't overwriting another file on the sd card?

since you are using the same filename each time it could be that the OS is ignoring thinks nothing is changed.

 

Trusted Contributor
QuestionMan
Posts: 167
Registered: ‎06-30-2011
My Device: n/a

Re: Can someone explain why this code isn't overwriting another file on the sd card?

Sorry, I borrowed this code for my own purposes so I'm pretty foggy as to its functions. i just did a run through in the simulator and noticed that the image was 'locked' in the actual folder. It said DRM Forward Lock. Now I've read a little about that and I thought it was a necessary part of this coding.

Anyway, I slashed out the forward lock line and now its appearing properly as the homescreen. So I guess its solved, but, what do you think the purpose of the lock is?
Developer
Developer
CMY
Posts: 1,123
Registered: ‎02-10-2009
My Device: 8130 / 8350 / 9530 / 9550 / 9850 / PlayBook

Re: Can someone explain why this code isn't overwriting another file on the sd card?

DRM ForwardLock keeps the file from being able to be transferred to another device.
Trusted Contributor
QuestionMan
Posts: 167
Registered: ‎06-30-2011
My Device: n/a

Re: Can someone explain why this code isn't overwriting another file on the sd card?

so I guess that doesn't really matter for my images, as long as the whole program can't be transferred correct?
Developer
Developer
CMY
Posts: 1,123
Registered: ‎02-10-2009
My Device: 8130 / 8350 / 9530 / 9550 / 9850 / PlayBook

Re: Can someone explain why this code isn't overwriting another file on the sd card?

The only thing that keeps it from being transferred is if you tie it to the device by means of the PIN.
Trusted Contributor
QuestionMan
Posts: 167
Registered: ‎06-30-2011
My Device: n/a

Re: Can someone explain why this code isn't overwriting another file on the sd card?

Ah true, I'll have to look into that more. Thanks for the help CMY