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
New Contributor
Posts: 2
Registered: ‎03-11-2010
My Device: 9000
My Carrier: dtac

ContentHandlerServer send to action problem

I try to develop an application that register "send to" action by use ContentHandlerServer. when the user take a picture and select sent to menu from camera viewer application i will create a post image screen and use this screen for send image to my server.

 

my problem is i can use sent to action only 1 time after close the post image screen i could not take "sent to" action until close camara application.

 

this is my code

 

   // Constructor
    public PostImageApp()
    {      
        try
        {
            // Get access to the ContentHandlerServer for this application and
            // register as a listener.
            ContentHandlerServer contentHandlerServer = Registry.getServer(CLASSNAME);
            contentHandlerServer.setListener(this);   
            this.addFileSystemJournalListener(new ImageListener(this));
            
        }
        catch(ContentHandlerException che)
        {
            errorDialog("Registry.getServer(String) threw " + che.toString());
        } 
    }
    
public void invocationRequestNotify(ContentHandlerServer server) 
    {	
        Invocation invoc = server.getRequest(false);     
        if(invoc != null)
        {
            String type = invoc.getType();            
            if(type.equals("image/bmp") || type.equals("image/png") || type.equals("image/jpeg"))
            {   
            	if (invoc.getURL().indexOf("null") != -1 ){
            		LoadPath();
            	}else{
            		_path = invoc.getURL();
            	}
            	DisplayScreen();            	
            }     
            else
            {
                System.exit(0);
            }            
            server.finish(invoc, Invocation.OK);        
        }    	
    } 

 

 

    public void DisplayScreen(){
    	synchronized (UiApplication.getEventLock()) {
			PostScreen postScreen = new PostScreen(_path, _postURL);
			UiApplication.getUiApplication().pushScreen(postScreen);
			UiApplication.getUiApplication().requestForeground();
		}
    	
    }

 

 

 I tested on simulator everything work fine, but the problem occurred only on device.

Bold 9000 software version: v. 5.0.0.464

 

Developer
Posts: 84
Registered: ‎09-21-2008
My Device: Not Specified

Re: ContentHandlerServer send to action problem

We have run into the same issue with 5.0.0.464 OS when using send to from the Camera. However, we have reports from many users of it happening on a number other 5.0 versions as well. I have been able to reproduce the issue on the BOLD 9000 5.0.0.464 simulator using the SendMediaDemo sample application, it appears to be a RIM bug.

 

The issue is that the invoke.getURL() is returning "file://nullnullnull", instead of the actual path to the image.

 

The most frustrating aspect of this issue is that it works perfectly fine for RIM built apps. I.E. Twitter for BlackBerry does not have an issue getting the image, which clearly means they are not using the same APIS as the rest of us, which basically makes 3rd party apps seem incompetent when there is nothing we can do about it.  

 

Another bug with these OS versions, if multiple applications register ContentHandlers, All of the "3rd party" buttons in the Send image listener invoke the application that was registered last (even though the buttons show the correct text for each individual application). This is not all that critical right now, since it simply does not work right now anyway, but it can give the impression to users that one application is breaking other applications. 

 

RIM, if your listening, you know testing the sample applications you provide is probably the very least the level of quality control that should be going on?? I mean, i'm sure there should be more, but come on, there are not that many sample apps, making sure they work is not out of the realm of reasonable expectations. 

Contributor
Posts: 40
Registered: ‎05-12-2010
My Device: multiple devices
My Carrier: multiple simcards

Re: ContentHandlerServer send to action problem

There is a workaround for this bug using FileSystemJournal.

 

The bug is here and the workaround is also described there: https://www.blackberry.com/jira/browse/JAVAAPI-963

 

 

Here you can see how i use it in my app:

 

 

public void invocationRequestNotify(ContentHandlerServer server) {
		Invocation invoc = server.getRequest(false);
		if (invoc != null) {
			String type = invoc.getType();
			String url = invoc.getURL();
			byte[] data = invoc.getData();

			_log.info("invocationRequestNotify " + invoc + " type: " + type
					+ " url: " + url + " data.length: " + data.length);

			if (type.equals("image/bmp") || type.equals("image/png")
					|| type.equals("image/jpeg")) {

				if (url.equals("file://nullnullnull")) {
					url = null;
					// Not Supported due to Blackberry BUG
					// https://www.blackberry.com/jira/browse/JAVAAPI-963");
					// workaround this issue by querying the file journal and
					// getting the last file that has changed
					long nextUSN = FileSystemJournal.getNextUSN();
					for (long lookUSN = nextUSN - 1; lookUSN >= 0; lookUSN--) {
						FileSystemJournalEntry entry = FileSystemJournal
								.getEntry(lookUSN);

						if (entry == null) {
							// we didn't find an entry.
							break;
						}

						if (entry.getEvent() == FileSystemJournalEntry.FILE_ADDED) {
							url = "file://" + entry.getPath();
							break;
						}
					}
				}
				
				if(url!=null) {
					enqueueUploadRequest(url);
				}
			} else if (type.equals("video/3gpp") || type.equals("video/mp4")) {
				// we dont handle videos yet
			} else {
				_log.info("invocationRequestNotify unkown type " + type);

			}

			server.finish(invoc, Invocation.OK);
		}
	}

 

 

Developer
Posts: 84
Registered: ‎09-21-2008
My Device: Not Specified

Re: ContentHandlerServer send to action problem

thanks for pointing this out, very helpful