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
adnanyaseen
Posts: 17
Registered: ‎06-01-2012
My Device: 8520

Comparing online and local device date for an image? Need suggestions.

Hi, Previously I have posted this question in another thread but now I am making separate thread for this problem.

 

My scenario is that, I read the XML from online handler and get Images name from it. The XML also contains the updateTime of the Image. First I save the Images to the device without checking updateTime. Second time when I open the image I have to check that if the updateTime in the XML is updated then I have to re-download the image as well. As I am unable to check the MetaData so currently I do this by comparing Image file modifiedDate and XML updateTime. But can be cases where the device time is not correct. So i don't want to depend on the device time. Any Sugggestions?

 

I am reading an Image from an Online handler and saving the image on device using the following code,

 

FileConnection fc = (FileConnection) Connector.open(path+ _imagefullname);

OutputStream oStream = fc.openOutputStream();
oStream.write(IOUtilities.streamToBytes(httpInput));
oStream.flush();
oStream.close();
fc.close();
httpConnection.close();

 

I then read the image from device and create an EncodedImage from it. But by using enc.getMetaData() I am able to get the key names. But there values are always null. Is there any API through which I can manually add the MetaData? What should I do?

Developer
peter_strange
Posts: 19,609
Registered: ‎07-14-2008
My Device: Not Specified

Re: Comparing online and local device date for an image? Need suggestions.

Sorry I can't answer the question about putting metadata in the image you store - that does not seem to be possible, but I have never tried.

 

What I can say is that the time on the device and the time on the Server can be different, even when both are 'correct', because of time zone differences.  So you need to factor in Time Zones. 

 

Obviously if the date is set incorrectly on the device, then this is not going to work. 

 

I would have thought that in most cases the modified time on device will work, and if you get an image down where the XML Update date is after the time on the device (after factoring in any Time Zone differences, then the time on the device is clearly wrong and perhaps you should tell the user that. 

Contributor
adnanyaseen
Posts: 17
Registered: ‎06-01-2012
My Device: 8520

Re: Comparing online and local device date for an image? Need suggestions.

Yes I am neutralizing the both dates (online image date & device modified date) by adding/removing the Time Zone offset. But there is difference of 5 to 6 minutes. Lets say I downloaded the image and within 5 minutes I update the online image then Image on the device is never updated because device time is 5 to 6 minutes ahead of online time after removing offsets. This makes me think that if the device time is totally wrong. Lets say if it is 15 minute ahead then it will not update the image for 15 minutes and if the device time is 15 minutes behind then it will always update the image within 15 minutes. I need to somehow save the online time.

 

I also tried to append the online time with the Image name. Then I listed all the files in the directory and split the file names and check the name part of the file and returned the filename with time. But I am downloading images in 3 threads. 1 main thread with 2 parallel threads and online time is not available in threads. Also it makes code more messy. So i need alterntive to EXIF data. Thanks

Contributor
adnanyaseen
Posts: 17
Registered: ‎06-01-2012
My Device: 8520

Re: Comparing online and local device date for an image? Need suggestions.

[ Edited ]
 
Developer
maadani
Posts: 729
Registered: ‎05-04-2011
My Device: 9700

Re: Comparing online and local device date for an image? Need suggestions.

Hi @adnanyaseen

 

Try using this method instead of the regular FileConnection:

http://www.blackberry.com/developers/docs/5.0.0api/net/rim/device/api/io/file/ExtendedFileConnection...

 

Hope that helps,

 

E.

Contributor
adnanyaseen
Posts: 17
Registered: ‎06-01-2012
My Device: 8520

Re: Comparing online and local device date for an image? Need suggestions.

Thanks @maadani, I will check this out.

Contributor
adnanyaseen
Posts: 17
Registered: ‎06-01-2012
My Device: 8520

Re: Comparing online and local device date for an image? Need suggestions.

Hi @maadani, I have tried to use the ExtendedFileConnection. But image is till saved by the input stream of HttpConnection. ExtendedFileConnection cannot be used to read images from server. I have to create InputStream using HttpConnection. So basically the image is saved on device by HttpConnection and if I read the file through ExtendedFileConnection then it is of no use.

Contributor
adnanyaseen
Posts: 17
Registered: ‎06-01-2012
My Device: 8520

Re: Comparing online and local device date for an image? Need suggestions.

Also openRawOutputStream is mentioned in the description present in documentation,

 

"Opening an OutputStream through an openRawOutputStream, an openOutputStream or an openDataOutputStream is the same as opening an OutputStream.".

 

But there is no method named "openRawOutputStream" only openRawInputStream is present.

Developer
maadani
Posts: 729
Registered: ‎05-04-2011
My Device: 9700

Re: Comparing online and local device date for an image? Need suggestions.

Hi @adnanyaseen,

 

You can save the meta data in a separate location.

 

You can:

 

1. Add a metadata file for each image.

 

2. Have one index file which will hold the data for all files.

 

3. Save the metadata in the persistent storage.

 

4. Save the metadata in a DB.

 

Hope that helps,

 

E.

Contributor
adnanyaseen
Posts: 17
Registered: ‎06-01-2012
My Device: 8520

Re: Comparing online and local device date for an image? Need suggestions.

Can I read the MetaData directly from stream?