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
sivalingaraja
Posts: 157
Registered: ‎07-09-2009
My Device: Not Specified

Re: How to use FileJournalListener?

[ Edited ]

Thanks,

 

I am using Simulator 9350 with eclipse plugin.

 

Can you tell me the steps what you have done for taking image and return back?(Not programmatically)

 

Can anyone help me on this?

Message Edited by sivalingaraja on 07-30-2009 01:48 AM
Developer
Developer
rab
Posts: 283
Registered: ‎07-22-2008
My Device: Not Specified

Re: How to use FileJournalListener?

- The code I suggested above was extracted as is from a working app. So it should be working.

The first thing to debug is to make sure that FileSystemJournlaListner is called. Without it nothing will work.

For closing the camera using the event Injector, please look at the comment I mentioned in the closeCamera(). i.e

 

/**
 * Closes the camera using the EventInjector mechanism
 * Not efficient as the command depends on the menu item order that may differ from
 * one device to another.
 */

 

You may need to change the variable menuOrder to the corresponding value on the device or simulator ( in may case it was 6)

 

Rab

Developer
sivalingaraja
Posts: 157
Registered: ‎07-09-2009
My Device: Not Specified

Re: How to use FileJournalListener?

Thanks rab,

 

Why my application does not invoke the "fileJournalChanged()" method when I taken the picture in camera?

Instead it calling this method when I pressed the back button only.

 

Is it that correct place of coding or is any difference is there for running application in Simulator and Device?

 

Thanks in advance for your response,

Sivalingaraja

Developer
Developer
rab
Posts: 283
Registered: ‎07-22-2008
My Device: Not Specified

Re: How to use FileJournalListener?

sivalingaraja

I just tried your code on the Bold simulator and it worked fine. One trivial thing that I hope you are doing is to press on the truckball to take the picture once the camera is displayed. You click on the "Take Picture" button in your screen, the camera displays, then press on the truckball to actually take the picture. Then FileJournal gets called immediately.

 

Rab

Developer
sivalingaraja
Posts: 157
Registered: ‎07-09-2009
My Device: Not Specified

Re: How to use FileJournalListener?

Thanks rab,

 

I am using eclipse plugin for the application development for Storm.

 

I am running simulator 9530.

 

Can you explain the steps need to achieve this!

 

Thanks

Developer
Developer
rab
Posts: 283
Registered: ‎07-22-2008
My Device: Not Specified

Re: How to use FileJournalListener?

I just tried the same code on the 9500 simulator using the JDE 4.7 and it also worked fine. The listener gets called every time a picture is taken. However the closeCamera did not work and It is obvious since it was written for older devices with the trackball.

So I did nothing special, just copied your code, compiled it and invoked it from a menu item in one of my test apps.

 

The other alternative that you can consider ( if you do not care about supporting older OS versions) is to use the cameraDemo sample that comes with JDE 4.7. It uses new API for the camera. I also tested it as is and it worked fine too. It gives you more control on opening/closing and invoking the camera.

 

Rab

Developer
sivalingaraja
Posts: 157
Registered: ‎07-09-2009
My Device: Not Specified

Re: How to use FileJournalListener?

Thanks for the reply, rab.

 

I have tried in 9500 Simulator also and iniating the camera application through menu item also. But, with no luck I have not got the solution for this.

 

Do I need to do any settings in Simulator?

 

Can anyone help me with this?

Developer
sivalingaraja
Posts: 157
Registered: ‎07-09-2009
My Device: Not Specified

Re: How to use FileJournalListener?

Hi Experts,

 

Anybody there to help me on this?

Developer
Developer
rab
Posts: 283
Registered: ‎07-22-2008
My Device: Not Specified

Re: How to use FileJournalListener?

Well I am using BB JDE 4.6 and there is nothing special to set in the simulator.

Later on when you put it on the device you may need to set the eventInjector permission, but in your case you did not reach that stage yet.

I do not know if eclipse has different requirements.

 

Rab

Developer
sivalingaraja
Posts: 157
Registered: ‎07-09-2009
My Device: Not Specified

Re: How to use FileJournalListener?

Hi Experts,

 

Here is my full code:

 

 

import net.rim.blackberry.api.invoke.CameraArguments; import net.rim.blackberry.api.invoke.Invoke; import net.rim.device.api.io.file.FileSystemJournal; import net.rim.device.api.io.file.FileSystemJournalEntry; import net.rim.device.api.io.file.FileSystemJournalListener; import net.rim.device.api.system.Bitmap; import net.rim.device.api.system.EventInjector; import net.rim.device.api.system.KeypadListener; import net.rim.device.api.ui.*; import net.rim.device.api.ui.component.*; import net.rim.device.api.ui.container.*; public class test extends MainScreen implements FileSystemJournalListener { long _lastUSN; ButtonField btnTakePhoto; String capturedImgPath = ""; BitmapField bmp; Bitmap bmpImg; public test() { super(); UiApplication.getUiApplication().addFileSystemJournalListener(this); _lastUSN = FileSystemJournal.getNextUSN(); btnTakePhoto = new ButtonField("Take Picture"); btnTakePhoto.setChangeListener(TakePictureListener); add(btnTakePhoto); bmpImg = null; bmp = new BitmapField(bmpImg); add(bmp); } FieldChangeListener TakePictureListener = new FieldChangeListener(){ public void fieldChanged(Field field, int context) { doTakePicture(); } }; public void doTakePicture(){ UiApplication.getUiApplication().addFileSystemJournalListener(this); _lastUSN = FileSystemJournal.getNextUSN(); Invoke.invokeApplication(Invoke.APP_TYPE_CAMERA, new CameraArguments(CameraArguments.ARG_CAMERA_APP)); } public void fileJournalChanged() { long nextUSN = FileSystemJournal.getNextUSN(); String msg = null; String path = null; for (long lookUSN = nextUSN - 1; lookUSN >= _lastUSN && msg == null; --lookUSN) { FileSystemJournalEntry entry = FileSystemJournal.getEntry(lookUSN); if (entry == null) { break; } path = entry.getPath(); if (entry.getEvent() == FileSystemJournalEntry.FILE_ADDED) { switch (entry.getEvent()) { case FileSystemJournalEntry.FILE_ADDED: msg = "File was added."; break; case FileSystemJournalEntry.FILE_DELETED: msg = "File was deleted."; break; } } } _lastUSN = nextUSN; if ( msg != null ) { capturedImgPath = path; Dialog.alert(capturedImgPath); closeCamera(); } } private void closeCamera() { int menuOrder =6; EventInjector.invokeEvent(new EventInjector.KeyCodeEvent(EventInjector.KeyCodeEvent.KEY_DOWN, (char)Keypad.KEY_MENU, KeypadListener.STATUS_NOT_FROM_KEYPAD, 0)); EventInjector.invokeEvent(new EventInjector.TrackwheelEvent(EventInjector.TrackwheelEvent.THUMB_ROLL_DOWN, menuOrder, KeypadListener.STATUS_NOT_FROM_KEYPAD)); EventInjector.invokeEvent(new EventInjector.TrackwheelEvent(EventInjector.TrackwheelEvent.THUMB_CLICK, 1, KeypadListener.STATUS_NOT_FROM_KEYPAD)); String full_path = "file://"+capturedImgPath; } }

 

 

Hello experts, is anything wrong with this code?

 

Or

 

Is any problem with my Simulator?

 

I am using eclipse plugin for the development..

 

!!!! I would be very grateful if anybody help me on this.!!!