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
nikita18
Posts: 144
Registered: ‎08-18-2012
My Device: Blackberry Curve 8520
Accepted Solution

get location name through opencellid is not working..

[ Edited ]

Below is my code:

 

public final String getQueryString(){
				// Retrieves the cell id  
				String cellID = Integer.toString(GPRSInfo.getCellInfo().getCellId());  
				// Retrieves the Location Area Code.  
				String lac = Integer.toString(GPRSInfo.getCellInfo().getLAC());  
				// Retrieves the mobile country code.  
				String mcc = Integer.toHexString(RadioInfo.getMCC(RadioInfo  
				                .getCurrentNetworkIndex()));  
				// Retrieves the Location network Code.  
				String mnc = Integer.toHexString(RadioInfo.getMNC(RadioInfo  
				                .getCurrentNetworkIndex()));				
				String queryStr="http://www.opencellid.org/cell/get?key="+myapikey+"&mcc="+mcc+"&mnc="+mnc+"&cellid="+cellID+"&lac="+lac+"&fmt=txt";
				return queryStr;			
	}
	
	public void httpGetRequest(){
		HttpConnection conn = null;		
        InputStream in = null;
        StringBuffer buff = new StringBuffer();
        String result = "";     
        try {
        	conn=(HttpConnection) Connector.open(getQueryString());        	
                in = conn.openInputStream();               
                buff.append(IOUtilities.streamToBytes(in));
                result = buff.toString();
                System.out.println(result);              
        } catch (Exception ex) {
            System.out.println("====Exception: "+ex.getMessage());
        } finally {
            try {
                if (in != null) {
                    in.close();
                }
                conn.close();
            } catch (IOException e) {
            	 System.out.println("====Exception: "+e.getMessage());
            }
        }
	}

 

But the line highlighted above gives Exception:

 

Local connection timed out after ~12000

 

Please help.

Please use plain text.
Developer
nikita18
Posts: 144
Registered: ‎08-18-2012
My Device: Blackberry Curve 8520

Re: get location name through opencellid is not working..

Anybody who can answer my query?.. Stuck on it since a long time..

Thanks in advance..

Please use plain text.
Developer
peter_strange
Posts: 19,607
Registered: ‎07-14-2008
My Device: Not Specified

Re: get location name through opencellid is not working..

I don't think the problem here is related to OPen Cellid.  I think the problem is the http get code.

 

I would look at the sample httpdemo code to see what a GET should look like. 

 

And make sure you understand the connection method you are using.  The following network video will help::

http://supportforums.blackberry.com/t5/Java-Development/Networking-Transports-II/ta-p/446742

 

This will help too:

http://supportforums.blackberry.com/t5/Java-Development/Different-ways-to-make-an-HTTP-or-socket-con...

 

Now if you don't want to code connection strings yourself, look at ConnectionFactory.

 

But the most important thing is to review httpDemo and test this in the Simulator (with BES MDS Simulator running).  Try changing the URL it requests to match the URL your code creates and see what happens too. 

Please use plain text.