1

I'd like my user to take a picture as an attachment by using the built in camera.

Is there someway to invoke the camera on a button press and save the resulting taken picture?

2 Answers2

2

The other option is to use the BlackBerry Invoke API to start the native camera application and listen for a file system event:

Invoke.invokeApplication(Invoke.APP_TYPE_CAMERA, new CameraArguments());

then, later:

class FileExplorerDemoJournalListener implements FileSystemJournalListener {
    public void fileJournalChanged() {
        long nextUSN = FileSystemJournal.getNextUSN();
        for (long lookUSN = nextUSN - 1; lookUSN >= _lastUSN && msg == null; --lookUSN) {
            FileSystemJournalEntry entry = FileSystemJournal.getEntry(lookUSN);
            if (entry == null) {
                break; 
            }
            String path = entry.getPath();
            if (path != null) {
                if (path.endsWith("png") || path.endsWith("jpg") || path.endsWith("bmp") || path.endsWith("gif") ){
                    switch (entry.getEvent()) {
                        case FileSystemJournalEntry.FILE_ADDED:
                            //either a picture was taken or a picture was added to the BlackBerry device 
                            break;
                        case FileSystemJournalEntry.FILE_DELETED:
                            //a picture was removed from the BlackBerry device;
                            break;
                    }
                }
            }
        }
    }
}

Finally...

Application.addFileSystemJournalListener(new FileExplorerDemoJournalListener());

This will get you most of the way there... taken from: http://docs.blackberry.com/en/developers/deliverables/11942/Detect_when_img_is_added_or_removed_file_system_740288_11.jsp

okonomichiyaki
  • 8,355
  • 39
  • 51
  • Can you add more detail regarding the msg==null part of your for loop? – Rydell Mar 17 '11 at 22:07
  • Nope, I'm sorry I can't. It came from that RIM documentation link, and I can't seem to even find what it's referring to there. I took a look at our app and the matching for loop doesn't have that test. I think it might be a mistake in the docs. – okonomichiyaki Mar 18 '11 at 01:24
  • 1
    @Rydell.. Can you please let me know what is _lastUSN & msg in the sample code, if you have already used this. – Nilanchala Apr 09 '12 at 09:08
  • I am using this code to invoke camera.. can u tell me what is _lastUSN ? – Kinjal Shah Feb 27 '14 at 09:16
  • Sorry, this was from such a long time ago I do not recall the details of the API. If you Google for `FileSystemJournal.getNextUSN()` you will turn up a lot of docs and other code, so hopefully one of those sites has some explanation of what it is. Good luck. – okonomichiyaki Feb 27 '14 at 14:40