JDE HTTPConnection for Blackberry issues
So, I am using the HTTPConnection class, for example:
HttpConnection c =
(HttpConnection)Connector.open("http://147.117.66.165:8000/eggs.3gp");
Following what LOOK at is the correct way to do things in the Blackberry JDE API.
However, my code crashes if I try to do anything with the "c" variable.
.getType()
.getInputStream()
.getStatus()
all fail.
I can, however, get the url from it, and I can look at the "c" variable to know that it was actually created.
Did I manage to create a broken connection? Do I need to do something to actually do something with this connection? Under what circumstances will this happen (I know the link is good, I can use a Blackberry browser to visit it).
Am I just using HttpConnection wrong? How do I get it right?
source to share
I figured out what was wrong by finding some sample code that used HttpConnection, (at least I think that at least I can access all of these variables now). I have never added it as "Stream Connection" before (examples I saw when it passed from Connector to HTTPConnection).
StreamConnection s = null;
s = (StreamConnection)Connector.open("http://10.252.9.15/eggs.3gp");
HttpConnection c = (HttpConnection)s;
InputStream i = c.openInputStream();
System.out.println("~~~~~I have a connection?~~~~~~" + c);
System.out.println("~~~~~I have a URL?~~~~" + c.getURL());
System.out.println("~~~~~I have a type?~~~~" + c.getType());
System.out.println("~~~~~I have a status?~~~~~~" + c.getResponseCode());
System.out.println("~~~~~I have a stream?~~~~~~" + i);
player = Manager.createPlayer(i, c.getType());
Even though the stream is now successfully created, I am still having problems using it, but it could be because my connection is so slow.
source to share
What error is thrown on crashes? You can try adding "Connector.READ_WRITE" as the second argument to your open call - even if it's just "read-only" like GET, some OSes like 4.6 will throw an exception if you don't open it in read / records.
source to share
In my blog post, you should find everything you need: HttpRequest and HttpResponse Library for BB OS5 + "
And to invoke media in the app, you can either invoke the browser or directly from the app. You are probably better off using your browser like this:
BrowserSession invokeHighQuality = Browser.getDefaultSession();
invokeHighQuality.displayPage("URL goes here");
OR you can try this:
// CHAPI invocation
Invocation invoke = new Invocation(_data.getUrl(), null, BlackBerryContentHandler.ID_MEDIA_CONTENT_HANDLER, false,
null);
try {
Registry.getRegistry(YourAppClass.class.getName()).invoke(invoke);
} catch (Throwable t) {
}
source to share