I am trying to build a simple application for testing purpose in which I am making a simple Http connection .The code is running perfectly on the simulator but when I am testing the app on the real device it is not returning any response code. I think there is some error in http connection .
Here is the code that I am using for http connection:
httpConnection = (HttpConnection)Connector.open("http://www.google.com");
The device that I am using is Blackberry 8520 v5.0.0.592
Also give me some tips on how to do the debuging of any app from real device using eclipse plugin.
Thanks in advance.
If it is enough that your program works with OS 5.0+, then try using Network API:
ConnectionFactory f = new ConnectionFactory();
ConnectionDescriptor descr = f.getConnection("http://www.google.com");
HttpConnection connection = (HttpConnection) descr.getConnection();
That piece of code tries to use the first available connection type. You can fine tune it if you want.
Regarding debugging, just install BlackBerry Desktop Software, connect your 8520 with the USB cable and from eclipse, click Run -> Debug As... -> BlackBerry Device.
The connection factory worked perfectly on the new devices, but didn't work with some of the older ones like the curve and bold. This is what solved it for me:
BrowserField browserField = new BrowserField();
BrowserFieldRequest Req = new BrowserFieldRequest("http://www.yourserver.com/");
InputStream inputStream = browserField.getConnectionManager().makeRequest(Req).openInputStream();
Try to redirect the link using following code:
HttpConnection hc = (HttpConnection) Connector.open(url1);
hc.setRequestMethod(HttpConnection.GET);
hc.setRequestProperty("User-Agent", "Profile/MIDP-2.0 Configuration/CLDC-1.0");
InputStream is = null;
String location =hc.getHeaderField("Location");
HttpConnection hcc = (HttpConnection) Connector.open(location);
is = hcc.openDataInputStream();
Try to add transport to address
For example for connect via wi-fi :
httpConnection = (HttpConnection)Connector.open("http://www.google.com;interface=wifi");
Related
I want to download a file from a server via the internet with a BlackBerry app.
It is not important which protocol is used: FTP, HTTP or something else would be fine. I just need the user to click "download" button and then the app downloads this file from a server.
I have no idea how it can be done. I have tried a few solutions. In one I need a HttpConnectorFactory but this is not in my API.
I have searched for an answer to my question for days, but I haven't found a solution that works.
Links to solutions I have tried:
How to download an html file in a BlackBerry application
https://stackoverflow.com/questions/6290988/downloading-a-pdf-file-from-a-webserver-in-blackberry-java-application
Networking Helper Class
try this -
ConnectionFactory connFact = new ConnectionFactory();
ConnectionDescriptor connDesc = connFact.getConnection(your_url);
HttpConnection httpConn = (HttpConnection) connDesc.getConnection();
try {
httpConn.setRequestMethod(HttpConnection.GET);
InputConnection inputConn = (InputConnection) httpConn;
InputStream is = inputConn.openInputStream();
byte[] data =IOUtilities.streamToBytes(is);
//the value in data will be the bytes of your file.
// now if you want to save the file, you can do it here......
} catch (IOException e) {
e.printStackTrace();
}
I want to download data using HttpConnection , see the example below
class ConnectionThread extends Thread
{
public void run()
{
try{
showToast("in the run method");
HttpConnection conn = null;
String URL = "http://xxxxxxx.com/api/api.php?func=showAllCountries;interface=wifi";
conn = (HttpConnection)Connector.open(URL);
}catch(Exception e){
showToast(e+"");
}
}
while running above code , on simulator it says Java.io.IOException No Wi-Fi connection found , Though in manage connection i can see simultor is conncted with Wifi ,
please why this is happening
Please
use deviceside= false;
in simulator wifi is not possible, simulator will access your system network , once you are on real device wifi will work if it is enabled in device.
Follow this link on how to make connections.
Is it possible to connect to a remote database from my flex4.5 Mobile application ?
I am trying to develop a flex 4.5 mobile application and my data is in Oracle Database.
I choose Java as my back end technology. How can I call the java services from flex.
I wanted my mobile application to run on iOS devices.
Yes. You can connect to any database, as long as that database can be connected to via php or Java (possibly other server-side languages as well). It uses a remote call, similiar to Ajax (but faster).
You can use a RemoteObject component. RemoteObject components use the AMF protocol to send and receive data, while WebService and HTTPService components use the HTTP protocol. AMF is significantly faster than HTTP.
On the Flex Side:
<mx:RemoteObject id="Hello" destination="roDest">
<mx:method name="getHelloData"/>
</mx:RemoteObject>
On the Java side:
...
public void getHelloData() {
try{
InitialContext ctx = new InitialContext();
Object obj = ctx.lookup("/Hello");
HelloHome ejbHome = (HelloHome)
PortableRemoteObject.narrow(obj, HelloHome.class);
HelloObject ejbObject = ejbHome.create();
String message = ejbObject.sayHello();
}
catch (Exception e);
}
...
The code examples were taken from:
http://help.adobe.com/en_US/flex/accessingdata/WS2db454920e96a9e51e63e3d11c0bf69084-7fda.html#WS2db454920e96a9e51e63e3d11c0bf66651-7fd7
Trying to connect via Wi-Fi and I have an issue with the OS6 cd variable is null but it works on OS5
This is the url Strng: https://api3.popfax.com/index.php?service=Popfax;interface=wifi;interface=wifi
public ServiceConnectionBlackBerry(String s) throws IOException {
ConnectionFactory cf = new ConnectionFactory();
ConnectionDescriptor cd = cf.getConnection(s);
if (cd!=null){
connection = (HttpConnection) cd.getConnection();
}else {
System.out.println("Strng: "+s);}
}
can someone help please.
When using ConnectionFactory you should not append any connection information to your URL. So instead you should just pass https://api3.popfax.com/index.php?service=Popfax to your method.
Open a Wi-Fi HTTPS connection may help you.
thanks
I need to upload a file through http or ftp to the website in blackberry jde.
High level view: You open an OutputStream from an HttpConnection and write your data into that output stream. The main problem is going to be choosing which network connection to use (I recommend looking at this, unless you're on OS 5.0 which has a similar feature built in). As to uploading through FTP that will be somewhat more difficult as there is no support for FTP built into the BlackBerry API instead you'll have to look at using a SocketConnection and implementing part of FTP yourself.
Here's some code to get you started:
HttpConnection httpConn = (HttpConnection) Connector.open("<URL>");
FileConnection fileConn = (FileConnection) Connector.open("file:///<path>");
InputStream in = fileConn.openInputStream();
OutputStream out = httpConn.openOutputStream();
byte[] buffer = new byte[100];
int bytesRead = 0;
while((in.read(buffer) = bytesRead) > 0)
{
out.write(buffer, 0, bytesRead);
}
Of course you'll need to deal with exceptions, close the streams, check that it was uploaded successfully, etc