01-03-2012 10:42 AM - edited 01-03-2012 10:44 AM
Hello,
I've been searching through all the forums and still can't find an example on how to achieve this. Does anyone know how to invoke from my app the pictures explorer to let the user select either a picture from the gallery or take a photo from the camera? Like the foursquare app does when you select "upload a photo".
FYI, I am developing with version 5.0
Many thanks in advance.
01-03-2012 11:05 AM
01-03-2012 11:33 AM
Sorry, but I only found how to use file picker and the selection popup screen:
But I am not sure if this is what I am looking for. Before I go for those, are them a good approach for my purpose?
Thanks.
01-03-2012 03:35 PM
Hi @jromanoski
Check out this link:
http://208.74.204.192/t5/Java-Development/Invoke-t
E.
01-05-2012 07:35 AM
maadani,
Many thanks for your help. Now with this code:
try {
// Create an invocation instance with the specified URL
// where the file type is one of the media types supported
// by the media player.
Invocation invocation = new Invocation(null, null,
BlackBerryContentHandler.ID_MEDIA_CONTENT_HANDLER,
false, ContentHandler.ACTION_OPEN);
invocation
.setArgs(new String[] { BlackBerryContentHandler.MEDIA_ARGUMENT_VIEW_PICTU RES });
// Get the Registry object using the class name of the
// application
Registry _registry = Registry.getRegistry(Application
.getApplication().getClass().getName());
// Invoke the content handler.
_registry.invoke(invocation);
} catch (IOException e) {
System.out.println("Camera exception: " + e.getMessage());
}
I am being able to invoke the media application to let the user choose among camera or pictures in the device. Now, after taking the photo or selecting a picture, how to select the image in my application? Is filejournallistener the best approach inthis case?
Thanks again for your help.
Regards
01-05-2012 08:26 AM - edited 01-05-2012 08:52 AM
I think File picker may help you: This below code works for select a photo from the SDCard or Device Memory;
public class Ghi extends MainScreen
{
FilePicker filePicker;
ButtonField select;
byte data[];
public Ghi()
{
createGUI();
}
private void createGUI()
{
select=new ButtonField("save");
select.setChangeListener(new FieldChangeListener()
{
public void fieldChanged(Field field, int context)
{
callFilePicker();
}
});
add(select);
}
private void callFilePicker()
{
synchronized (UiApplication.getUiApplication().getAppEventLock( ))
{
filePicker=FilePicker.getInstance();
filePicker.setPath("file:///SDCard/BlackBerry/pict ures/");//Your desired path. Before giving "setPath" check SDCRAD is present or not
filePicker.setListener(new Listener()
{
public void selectionDone(String selectedPath)
{
try
{
System.out.println("======================URL: "+selectedPath);
FileConnection file = (FileConnection)Connector.open(selectedPath);
// Do what ever you want. Means Take the picture in to Byte array and
// do something;
file.close();
}
catch (Exception e)
{
StartUp.exceptionHandling(e.getMessage());
}
}
});
filePicker.show();
}
}
}
//Here url nothing but the path up to your selected pictureName;
//if "sdcard" present then filePicker.setPath("file:///SDCard/BlackBerry/pict ures/");
//else filePicker.setPath("file:///store/home/user/pictur es/");
This works for selecting the pictures and do something;
==================================================
Feel free to click like button
01-05-2012 08:43 AM
You might find this Thread useful for selecting the Camera image last taken.
http://supportforums.blackberry.com/t5/Java-Develo
01-05-2012 09:46 AM
@alishaik786
The code you posted only works for selecting an image from the library. I want to let the user either select the image from the library or take the photo...
01-05-2012 10:37 AM
To do that I think you are going to have to use a combination of what I can you and what alishaik786 gave you. Not sure though, never done it.
01-05-2012 10:45 AM
Thanks Peter. Yes I was thinking the same, though seems strange because I've seen lots of apps doing the same thing (Foursquare, Facebook, Tuenti...) and it seems pretty easy to implement.
I'll keep this thread updated in case i have some good news...