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

How to use FileJournalListener?

Hi Guys,

 

I want to open camera and take the photo from my application. And, when user taken the photo then I  want to redirect them to my application. I tried to use the filejournallistener but I don't know how to take the user back to my application when they taken photo.

Here is code I have used to use the file journal listener and invoking camera application.

 

public void takePicture(){ _fileListener = new MyFileJournalListener(this); UiApplication.getUiApplication().addFileSystemJournalListener(_fileListener); Invoke.invokeApplication(Invoke.APP_TYPE_CAMERA, null); }

 

I am new to development. 

 

Can anyone tell me :

 

1. How to take the user back to my application and where I have to use that code?

2. How to use the file journal listener?

 

Thanks in advance for your response,

Sivalingaraja

 

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

Re: How to use FileJournalListener?

- First assume that you have a class/screen that you are going to use. Make it implement the interface FileSystemJournalListener as follows:

 

public class SnapScreen extends MainScreen  implements FileSystemJournalListener

 

-  In the constructor add the following:

 

    UiApplication.getUiApplication().addFileSystemJournalListener(this);
    long _lastUSN = FileSystemJournal.getNextUSN();

 

 

- Then make SnapScreen implement the following method:

 

/** * Notified when FileSystem event occurs.

*/ public void fileJournalChanged() { long nextUSN = FileSystemJournal.getNextUSN(); String msg = null; for (long lookUSN = nextUSN - 1; lookUSN >= _lastUSN && msg == null; --lookUSN) { FileSystemJournalEntry entry = FileSystemJournal.getEntry(lookUSN); if (entry == null) { // we didn't find an entry. break; } //check if this entry was added or deleted String path = entry.getPath(); if (path != null) { switch (entry.getEvent()) { case FileSystemJournalEntry.FILE_ADDED: msg = " File Added: "+entry.getPath(); _fileFullName = entry.getPath(); if(_fileFullName.endsWith("jpg")) AddFileToDisplay();// or whatever you want to do with the image break; case FileSystemJournalEntry.FILE_DELETED: msg = " File Deleted: "+entry.getPath(); _fileFullName = entry.getPath(); break; } } } // _lastUSN must be updated before calling showMessage() because that method // pushes a modal screen onto the display stack, which blocks this thread. // If the modal screen's thread then processes a file journal event on this // application's behalf, the for loop above can end up processing the same // event that we are blocking on. Updating _lastUSN before blocking prevents // the same file journal event from being processed twice, and thus prevents // the same dialog from being displayed twice. _lastUSN = nextUSN; if ( msg != null ) { System.out.println(msg); // MobileMainScreen.singleton().showAlert(msg); } }

 

 

And to close the camera and come back to your application use something like the following: ( Note: this code is old, there could be new ways of doing it with the new JDE ):

 

 

/** * 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. */ 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)); }

 

 

 

Rab

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

Re: How to use FileJournalListener?

Thanks for the reply, rab.

 

 

I have tried like above what you mentioned.

 

But I quite confused when & where I need to invoke the camera application and in which place I have to use closecamera() method.

 

Can you please help me.

 

Thanks in advance for your response,

Sivalingaraja.

 

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

Re: How to use FileJournalListener?

You can call closecamera when the New file get added in File System.

Use Search. "Accept Solution" If the problem is resolved.
Developer
Posts: 157
Registered: ‎07-09-2009
My Device: Not Specified

Re: How to use FileJournalListener?

Thanks BBDeveloper,

 

Here is the code what I am trying:

 

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.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 = ""; public test() { super(); btnTakePhoto = new ButtonField("Take Picture"); btnTakePhoto.setChangeListener(TakePictureListener); add(btnTakePhoto); UiApplication.getUiApplication().addFileSystemJournalListener(this); _lastUSN = FileSystemJournal.getNextUSN(); } FieldChangeListener TakePictureListener = new FieldChangeListener(){ public void fieldChanged(Field field, int context) { doTakePicture(); } }; public void doTakePicture(){ Invoke.invokeApplication(Invoke.APP_TYPE_CAMERA, null); } 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 (path != null) { 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 ) { Dialog.alert(msg); capturedImgPath = path; 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)); Dialog.alert("The captured Image path is "+capturedImgPath); } }

 

I have executed in simulator and when I pressed capture button in camera application it did not closed the camera. When I used the back button then only it calling the fileJournalChanged() method..

 

Any idea in this?

 

Thanks in advance for your response.

Sivalingaraja

 

 

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

Re: How to use FileJournalListener?

First thing I would suggest you to debug why the FileSystem didn't trigger the file added. If this works, you can call your closecamera method there.

Use Search. "Accept Solution" If the problem is resolved.
Developer
Posts: 157
Registered: ‎07-09-2009
My Device: Not Specified

Re: How to use FileJournalListener?

Thanks for the reply,

 

I have tried to find out the reason for the FileSystem didn't trigger the file added. But, I can't find the reason.

 

I am using eclipse plugin (version 4.7.0) for the development.

 

Is that programming code is correct or I need to change anything?

 

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

Re: How to use FileJournalListener?

 

 path = entry.getPath(), wht is it returning? Did you check is this still null? Can you check for the event directly.. something like this..

 

 if (entry.getEvent() == FileSystemJournalEntry.FILE_ADDED)

 

 


Use Search. "Accept Solution" If the problem is resolved.
Developer
Posts: 157
Registered: ‎07-09-2009
My Device: Not Specified

Re: How to use FileJournalListener?

Thanks, BBDeveloper,

 

I have tried by modified the path!=null with entry.getEvent() == FileSystemJournalEntry.FILE_ADDED.

 

But, unluckily I have not found the solution.

 

Is there any difference with Simulator and Stord device for this?

 

Is this code is working for you? (Have you tried with this code?)

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

Re: How to use FileJournalListener?

I had tried that code, It is worked for me. I dn't rememebr which Simulator was that.

Use Search. "Accept Solution" If the problem is resolved.