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
JoVinz
Posts: 255
Registered: ‎05-03-2012
My Device: 9930

Set ConnectionTimeout

[ Edited ]

How to set and handle connectiontimeout ? here is my code. I have used "ConnectionTimeout" parameter. But its not working .After timeout,Screen becomes blank. Plz someone Help. Its urgent

private static String getConnectionString()
{
String strConnectionString="";

if(DeviceInfo.isSimulator())
{
if(HttpUtils.USE_MDS_IN_SIMULATOR)
{
strConnectionString = ";deviceside=false";
}
else
{
strConnectionString = ";deviceside=true";
}
}
else if(WLANInfo.getWLANState()==WLANInfo.WLAN_STATE_CONNECTED)
{
strConnectionString = ";interface=wifi";
}
else if((CoverageInfo.getCoverageStatus() & CoverageInfo.COVERAGE_DIRECT) == CoverageInfo.COVERAGE_DIRECT)
{
String carrierUid = getCarrierBIBSUid();
if(carrierUid == null)
{
strConnectionString = ";deviceside=true";
}
else
{
strConnectionString = ";deviceside=false;connectionUID="+carrierUid + ";ConnectionType=";
}
}
else if((CoverageInfo.getCoverageStatus() & CoverageInfo.COVERAGE_MDS) == CoverageInfo.COVERAGE_MDS)
{
strConnectionString = ";deviceside=false";
}
else if(CoverageInfo.getCoverageStatus() == CoverageInfo.COVERAGE_NONE)
{
//Dialog.alert("OOPS!!! Check your connection...");
}
else
{
strConnectionString = ";deviceside=true";
}
return strConnectionString;
}

private static String getCarrierBIBSUid()
{
ServiceRecord[] records = ServiceBook.getSB().getRecords();
int currentRecord;

for(currentRecord = 0; currentRecord < records.length; currentRecord++)
{
if(records[currentRecord].getCid().toLowerCase().equals("ippp"))
{
if(records[currentRecord].getName().toLowerCase().indexOf("bibs") >= 0)
{
return records[currentRecord].getUid();
}
}
}
return null;
}

public static String getUrlWithConnection(String strUrl)
{
return strUrl+getConnectionString()+";ConnectionTimeout=45000";
}

 

public static InputStream getInputStream( String url)
{
url = getUrlWithConnection(url);
if(CoverageInfo.isOutOfCoverage())
{
return null;
}
HttpConnection _c = null;
InputStream _is = null;
try
{
_c = (HttpConnection)Connector.open(url);
int rc = _c.getResponseCode();
if (rc != HttpConnection.HTTP_OK)
{
return null;
}

_is = _c.openInputStream();
}
catch (Exception e)
{
}
return _is;
}

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

Re: Set ConnectionTimeout

Handling timeouts has been covered in a number of Threads on the forum.  Please search for other Threads that discuss this for the available options.  Also review the documentation that describes connectionTimeout to determine when it is applicable. 

Please use plain text.