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
Kiran_Snist
Posts: 174
Registered: ‎01-25-2011
My Device: Not Specified

How to identify the photo selection done in media!!

Hi frds,

 

I am trying to implement photo picker as selected frm the media opened frm the app using the below code :

		Invocation invocation = new Invocation(null, null,
				BlackBerryContentHandler.ID_MEDIA_CONTENT_HANDLER, false,
				ContentHandler.ACTION_OPEN);

		invocation
				.setArgs(new String[] { BlackBerryContentHandler.MEDIA_ARGUMENT_VIEW_PICTURES });

		// Get the Registry object using the class name of the
		// application
		Registry _registry = Registry.getRegistry(Application.getApplication()
				.getClass().getName());

		// Invoke the content handler.
		try {
			_registry.invoke(invocation);
		}  catch (Exception e) {
			e.printStackTrace();
		}

 I m able to open the media pics succesfully, but how can I recognize that the user has selected an image... so that i can perform some sort of actions soon after selection is done.. I have tried filePicker but i didnt had any luck.. is der any other way to identify the photo selection??? 

 

Thanx in advance

Please use plain text.
Regular Contributor
nyerunkar
Posts: 74
Registered: ‎12-30-2010
My Device: Blackberry Bold 9700
My Carrier: Vodafone.

Re: How to identify the photo selection done in media!!

have you got any success for your problem ...?

 

if yes then please let me know

 

Thanks .,

Nilesh

Thanks .,
Nilesh .
Please use plain text.
Developer
maadani
Posts: 729
Registered: ‎05-04-2011
My Device: 9700

Re: How to identify the photo selection done in media!!

AFAIK, you can't get the selected image.

 

You can try and add an application menu to images or trying to implement your own photo picker.

 

E.

Please use plain text.
Developer
Kiran_Snist
Posts: 174
Registered: ‎01-25-2011
My Device: Not Specified

Re: How to identify the photo selection done in media!!

[ Edited ]

Any help????  .. I want the to do, the same functionality the is done by the contacts application when user try to add the contact image ... How could i acheve it???.. 

Please use plain text.
New Developer
ajaysinghBB
Posts: 21
Registered: ‎07-26-2012
My Device: 9790
My Carrier: airtel

Re: How to identify the photo selection done in media!!

Any one get the solution????

Please use plain text.
Developer
kamal_nigam
Posts: 434
Registered: ‎07-23-2012
My Device: Blackberry 10
My Carrier: Orange

Re: How to identify the photo selection done in media!!

if you are using 5.0+ than use FilePicker API.

 

 

import net.rim.device.api.ui.picker.FilePicker;
import net.rim.device.api.ui.picker.FilePicker.Listener;

public class FilePickerScreen extends MainScreen implements FieldChangeListener
{       
Bitmap bitmap;
ButtonField click;
BitmapField bitmapField;
public FilePickerScreen()
{   
    setTitle("FilePicker Screen");
    createGUI();
}

private void createGUI() 
{   
    add(new LabelField("Click to select the image", Field.FIELD_HCENTER));
    click=new ButtonField("Click");
    click.setChangeListener(this);
    add(click);         
    bitmapField=new BitmapField();
    add(bitmapField);
}   

private Bitmap getTheImage(String url) 
{
    Bitmap bitmap=null,scaleBitmap=null;
    InputStream inputStream=null;
    FileConnection fileConnection=null;     
    try
    {
        fileConnection=(FileConnection) Connector.open(url);
        inputStream=fileConnection.openInputStream();           
        byte[] data=new byte[(int)fileConnection.fileSize()];           
        data=IOUtilities.streamToBytes(inputStream);
        inputStream.close();
        fileConnection.close();
        bitmap=Bitmap.createBitmapFromBytes(data,0,data.length,1);

        //You can return this bitmap otherwise, after this you can scale it according to your requirement; like...
        scaleBitmap=new Bitmap(150, 150);
        bitmap.scaleInto(scaleBitmap, Bitmap.FILTER_LANCZOS);           
    }
    catch (Exception e) 
    {
        try 
        {
            if(inputStream!=null)
            {
                inputStream.close();                
            }
            if(fileConnection!=null)
            {
                fileConnection.close();
            }
        } 
        catch (Exception exp) 
        {

        }
        scaleBitmap=Bitmap.getBitmapResource("noimage.png");//Your known Image;     
    }
    return scaleBitmap;
}

public void fieldChanged(Field field, int context)
{
    if(field==click)
    {
        try 
        {
            FilePicker filePicker;
            filePicker=FilePicker.getInstance();
            filePicker.setPath("file:///SDCard/BlackBerry/pictures/");
            filePicker.setListener(new Listener() 
            {       
                public void selectionDone(String path)
                {
                    bitmapField.setBitmap(getTheImage(path));
                }
            });
            filePicker.show();//it show what ever you select.
        } 
        catch (Exception e) 
        {
            StartUp.exceptionHandling(e.getMessage());
        }
    }       
}   
}
Thanks
-------------------------------------------------------------------------------------
Press the Accept as solution Button when u got the Solution
Press Kudo to say thank to developer.
-------------------------------------------------------------------------------------.
Please use plain text.
Developer
kamal_nigam
Posts: 434
Registered: ‎07-23-2012
My Device: Blackberry 10
My Carrier: Orange

Re: How to identify the photo selection done in media!!

you can chk this link also

 

http://supportforums.blackberry.com/t5/Java-Development/Display-Thumbnails-and-create-a-Photo-Picker...

 

Thanks
-------------------------------------------------------------------------------------
Press the Accept as solution Button when u got the Solution
Press Kudo to say thank to developer.
-------------------------------------------------------------------------------------.
Please use plain text.