views:

263

answers:

1

Hello,

My BlackBerry application is using a BrowserSession to open up a web page. When the web page opens up, the user will type in their login credentials, and then they are forwarded to a new website which tells them to close the BlackBerry Browser and return to my application. (...OAuth authentication)

Now, I am trying to see if I can do one of the following:

  • Create a custom URI scheme for my application, so that the website can forward to an address such as "myapp://..." and my application will open up. I have been researching online and on the forums about this, and I don't think its possible. I have been searching a lot about JSR 211 and content handlers and MIME types. I also looked into the chapidemo demo in the JDE samples.

  • Close the BrowserSession. I know that I cannot do this from within my application. I successfully moved my application to the foreground after my application made a successful http request, but the browser comes BACK to the foreground when the website forwards to the new page (which tells the user to close the browser)

  • Somehow determine the URL of the current BrowserSession. If I could do that, then I could have my application to the foreground when I recognize the URL of the page that was forwarded to.

Unfortunately, I cannot use a BrowserField because the site that I open up in the browser needs to support javascript and ajax...I tried this in the BrowserField, and it didn't work.

Does anyone have any advice or suggestions?

Thanks!


Update:

My code to register:

BrowserContentProviderRegistry converterRegistry = BrowserContentProviderRegistry
                .getInstance();
        if (converterRegistry != null) {
            converterRegistry.register(new BrowserPlugin());
        }
+1  A: 

You could use the BrowserContentProviderRegistry class to register a custom BrowserContentProvider implementation for your app with a custom MIME type. When OAuth is done, have it redirect to a page on your website that serves up a document with that MIME type. This will cause your BrowserContentProvider to be executed which can then do anything you like, such as bring your application back into the foreground.

Marc Novakowski
Thanks for your response, Marc. I will try this out and post my results...
behrk2
Marc, would I also need to register the application (on startup) as an HttpFilter? I'm looking at the following link: http://docs.blackberry.com/en/developers/deliverables/652/BlackBerry_Application_Developer_Guide_Volume_2.pdf
behrk2
Nope, a BrowserContentProvider is all you need. See the BrowserPlugin.java sample app for an example. The actual "content" the plugin returns can be empty (i.e. an empty HorizontalFieldManager) but the important thing is that you can run whatever code you want in its getBrowserContent method, including code to bring your app to the foreground.
Marc Novakowski
I have everything all set up: The LoaderApp, the BrowserContentProvider, and the file on my web server with the correct mime type. I am instantiating the LoaderApp right before i open up a new instance of a BrowserSession. Is there something that I am supposed to do to link the BrowserSession to the BrowserPlugin?
behrk2
Once you register a BrowserContentProvider in the registry it stays in there, even when your app is shut down. Have you tried putting logging in your BrowserContentProvider to see if its methods are being called?
Marc Novakowski
I tried it, and the methods were not being called. So, I moved the instantiation of the BrowserContentProviderRegistry to when the application starts, and I received a ControlledAccessException which, according to the BrowserContentProvider API, means that the exception will be thrown "if one or more MIME type browserContentProvider supports is already registered with the browser". Is it the case the BlackBerry browser already supports the application/x-vnd.rim.xxxtest mime type? Thanks
behrk2
I haven't had problems re-registering the same mime type for the same application multiple times. Like you I put the registration code in the app startup. The ControlledAccessException could also be thrown if the application permissions are not set to "allow".
Marc Novakowski
Got it working by registering the mime type in a separate Library project that launches at startup, and I had to add the mime type to my web server. Thanks!
behrk2