If you are using Internet Explorer, please remove blackberry.com from your compatibility view settings.

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
Contributor
ratheesh
Posts: 26
Registered: ‎07-04-2011
My Device: curve 9300
My Carrier: airtel

MY App is Not working in BIS (Nigeria)

Dear All,

 

I have develped social networking  App in Blackberry which uses some  data from a remote database so i ses http connection for this.The app is working correctly in both wifi and BIS here(*india). I have use the following class to add the connection suffix to the http connection.

 

package com.clique.blackberry;

import net.rim.device.api.servicebook.ServiceBook;
import net.rim.device.api.servicebook.ServiceRecord;
import net.rim.device.api.system.CoverageInfo;
import net.rim.device.api.system.DeviceInfo;
import net.rim.device.api.system.RadioInfo;
import net.rim.device.api.system.WLANInfo;
import net.rim.device.api.ui.container.MainScreen;

public class conIdentify extends MainScreen{
static String suffix="",carrier_name="";public static boolean conflag=true;
public conIdentify(){
}

public static String getConnectionSuffix(){

if(DeviceInfo.isSimulator())
{
suffix=";deviceside=true";
}
else if((WLANInfo.getWLANState()==WLANInfo.WLAN_STATE_CONNECTED)&&(RadioInfo.areWAFsSupported(RadioInfo.WAF_WLAN))){
suffix=";deviceside=true;interface=wifi";
}
else if((CoverageInfo.getCoverageStatus()&CoverageInfo.COVERAGE_DIRECT)==(CoverageInfo.COVERAGE_DIRECT)){
String Carrier=getCarrier();
if(Carrier==null){
suffix=";deviceside=true";
//Dialog.alert("nullon"+Carrier);
}
else{
//Dialog.alert("yes"+Carrier);


suffix=";deviceside=false;ConnectionSetup=delayed;UsePipe= true;ConnectionUID="+Carrier+";EncryptRequired=true";

}
}
else if((CoverageInfo.getCoverageStatus()&CoverageInfo.COVERAGE_MDS)==CoverageInfo.COVERAGE_MDS){
suffix=";deviceside=false";

}
else if(CoverageInfo.getCoverageStatus()==CoverageInfo.COVERAGE_NONE){
//Dialog.alert("Sorry ");
conflag=false;
// noActivity(conflag);
}
else{
suffix=";deviceside=true";
}
System.out.println("CONNECTION SUFFIX......"+suffix);
return suffix;



}

public static String getCarrier(){
ServiceRecord[] s_rec=ServiceBook.getSB().getRecords();
//Dialog.alert("sb "+s_rec[1]);
int c_rec;
for(c_rec=0;c_rec<s_rec.length;c_rec++){
// Dialog.alert("sb "+s_rec[c_rec].getCid());
if(s_rec[c_rec].getCid().toLowerCase().equals("ippp")){

return s_rec[c_rec].getUid();

}
}
return null;
}

}

 

 

The issue is when i send this app to nigeria , the app is not working in nigeria (BIS) . it says not connect to internet  ...

1.have any difference in bis connection of india and nigeria ?

2.If all the network related app uses the above code for making internet connection?

3. if any error in the above code?

4. we need any modification to the above code?

PLEASE REPLY IT IS URGENT.......

 

Please use plain text.
Developer
pradeep_ch
Posts: 543
Registered: ‎12-23-2010
My Device: Z10
My Carrier: Airtel

Re: MY App is Not working in BIS (Nigeria)

Hi rateesh,

 

You are mentioning about BIS, but  I am not able to find it out in your code.

try to add this snippet to your code and try to check connectionType,

Also you can find a lot of posts from Peter about connections.

 

if ((coverageStatus & CoverageInfo.COVERAGE_BIS_B) == CoverageInfo.COVERAGE_BIS_B) {
                    connParams = ";deviceside=false;ConnectionType=mdshypenpublic";
                }

 

Thanks.

Please use plain text.
Contributor
ratheesh
Posts: 26
Registered: ‎07-04-2011
My Device: curve 9300
My Carrier: airtel

Re: MY App is Not working in BIS (Nigeria)

thanks for the reply....

 

i have given that case to my code ..but still the app takes this case and it is not going to the BIS case...

else if((CoverageInfo.getCoverageStatus()&CoverageInfo.COVERAGE_DIRECT)==(CoverageInfo.COVERAGE_DIRECT)){
String Carrier=getCarrier();
if(Carrier==null){
suffix=";deviceside=true";
//Dialog.alert("nullon"+Carrier);
}
else{
//Dialog.alert("yes"+Carrier);


suffix=";deviceside=false;ConnectionSetup=delayed;UsePipe= true;ConnectionUID="+Carrier+";EncryptRequired=true";

}
}

 

thanks 

 

Please use plain text.
Regular Contributor
kamaleshpandey
Posts: 91
Registered: ‎11-10-2009
My Device: BB 9810
My Carrier: Generic

Re: MY App is Not working in BIS (Nigeria)

Hi,

If you are working with 5.0 OS onward you can use ConnectionFactory, that is much easy to handle.

 

int[] preferredTransportTypesWithBIS = { TransportInfo.TRANSPORT_TCP_WIFI, TransportInfo.TRANSPORT_BIS_B, TransportInfo.TRANSPORT_MDS,
TransportInfo.TRANSPORT_TCP_CELLULAR, TransportInfo.TRANSPORT_WAP2, TransportInfo.TRANSPORT_WAP };

 

ConnectionFactory connectionFactory = new ConnectionFactory();
connectionFactory.setPreferredTransportTypes(preferredTransportTypesWithBIS);
connectionFactory.setTransportTypeOptions(TransportInfo.TRANSPORT_BIS_B, new BisBOptions(" BIS param "));

 

ConnectionDescriptor connd = null;
connd = connectionFactory.getConnection(url);

HttpConnection httpConnection = (HttpConnection) connd.getConnection();

Kamalesh
Please use plain text.
Contributor
ratheesh
Posts: 26
Registered: ‎07-04-2011
My Device: curve 9300
My Carrier: airtel

Re: MY App is Not working in BIS (Nigeria)

my app will support the os 6.0 and above.. so I only want to make the http connection for the OS 6.0 and above.

I dont know how to intergrate connection factory class in the above code. i would like to know how all other apps are working in both bis and wifi. explain how to make a code which supports all connections.

 

Thanks In Advanec

Ratheesh C.N 

 

Please use plain text.
Regular Contributor
kamaleshpandey
Posts: 91
Registered: ‎11-10-2009
My Device: BB 9810
My Carrier: Generic

Re: MY App is Not working in BIS (Nigeria)

ConnectionFactory take care of all.

You can define order or specification in preferredTransportTypesWithBIS.

 

For BIS we have to pass BIS param, for that it has separate option to set the param.

 

For other like wifi, wap2 etc ConnectionFactory take care.

I hope you must have taken RIM authorization for using BIS. 

 

 

Kamalesh
Please use plain text.
Contributor
ratheesh
Posts: 26
Registered: ‎07-04-2011
My Device: curve 9300
My Carrier: airtel

Re: MY App is Not working in BIS (Nigeria)

I have activated BIS connection(idea )on my device(blackberry bold 9900) . the app is working both wifi and edge in my device using the previous connection suffix code. but i given this app to nigeria they cant connect it using BIS . 

 

 

I have reaserched abt connection factery class and i got some ideas . for using bis we need any RIM authorization ?

 

Please use plain text.
Regular Contributor
kamaleshpandey
Posts: 91
Registered: ‎11-10-2009
My Device: BB 9810
My Carrier: Generic

Re: MY App is Not working in BIS (Nigeria)

Hi,

Having BIS activated connection doesn't mean that you can you BIS channel for making http connection.

Moreover I also have worked one of mine Nigeria client and I used connectionfactery in same way what I told you it works there.

 

I hope you must have BIS parameter "*********", for us our client register membership with RIM to get BIS param.

See this param is just a string you can use that if you know but for commercial purpose I guess it may fail in RIM guideline.

 

I have attached a sample code for you

public class HttpClient {
 
 
private ConnectionFactory connectionFactory;
private HttpConnection httpConnection = null;
 
 
 
protected int[] preferredTransportTypesWithBIS = { TransportInfo.TRANSPORT_TCP_WIFI, TransportInfo.TRANSPORT_BIS_B, TransportInfo.TRANSPORT_MDS,
TransportInfo.TRANSPORT_TCP_CELLULAR, TransportInfo.TRANSPORT_WAP2, TransportInfo.TRANSPORT_WAP };
 
public static final int GET_STRING = 0;
public static final int GET_INPUTSTREAM = 1;
public static final int GET_BYTEARRAY = 2;
 
public static boolean doSleep = false;
 
public HttpClient() {
connectionFactory = new ConnectionFactory();
connectionFactory.setPreferredTransportTypes(preferredTransportTypesWithBIS);
connectionFactory.setTransportTypeOptions(TransportInfo.TRANSPORT_BIS_B, new BisBOptions("***********"));
 
}
 
private void setPermissions(Hashtable properties, HttpConnection httpConn) {
if ((properties != null) && (properties.size() > 0)) {
 
Enumeration keysEnum = properties.keys();
 
while (keysEnum.hasMoreElements()) {
String key = (String) keysEnum.nextElement();
String val = (String) properties.get(key);
try {
httpConn.setRequestProperty(key, val);
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
 
 
public Object[] doPost(String url, String postData, Hashtable properties, int returnType) throws Exception {
httpConnection = null;
OutputStream os = null;
StringBuffer buffer = new StringBuffer();
Object[] data = new Object[3];
boolean dataTooLarge = false;
 
 
try {
if ((url == null) || url.equalsIgnoreCase("") || (connectionFactory == null)) { return null; }
 
ConnectionDescriptor connd = null;
connd = connectionFactory.getConnection(url);
ConsoleLogProvider.logOnConsole(this.getClass().getName(), ConsoleLogProvider.DEBUG, "ConnectionDescriptor is " + connd);
if (connd != null) {  
httpConnection = (HttpConnection) connd.getConnection();
if (httpConnection != null) {
setPermissions(properties, httpConnection);
try {
// post data
if (postData != null) {
httpConnection.setRequestMethod(HttpConnection.POST);
os = httpConnection.openOutputStream();
os.write(postData.getBytes());
 
} else {
httpConnection.setRequestMethod(HttpConnection.GET);
}
 
} catch (Exception e) {
e.printStackTrace();
 
}
 
int resCode = httpConnection.getResponseCode();
switch (resCode) {
 
case HttpConnection.HTTP_OK: {
 
InputStream inputStream = httpConnection.openInputStream();
int c;
while ((c = inputStream.read()) != -1) {
buffer.append((char) c);
}
 
inputStream.close();
 
switch (returnType) {
case GET_STRING:
data[GET_STRING] = new String(buffer.toString().trim().getBytes(), "UTF-8");
break;
case GET_INPUTSTREAM:
ByteArrayInputStream bais = new ByteArrayInputStream((buffer.toString().trim()).getBytes());
data[GET_INPUTSTREAM] = (InputStream) bais;
break;
case GET_BYTEARRAY:
data[GET_BYTEARRAY] = (buffer.toString().trim()).getBytes();
break;
 
}
 
break;
}
 
case HttpConnection.HTTP_BAD_REQUEST: {
if (returnType == GET_STRING) {
buffer.append(HttpConnection.HTTP_BAD_REQUEST);
}
data[GET_STRING] = buffer.toString().trim();
break;
}
 
case HttpConnection.HTTP_NOT_FOUND:
data[GET_STRING] = buffer.toString().trim();
break;
 
case HttpConnection.HTTP_FORBIDDEN: {
 
if (returnType == GET_STRING) {
buffer.append(HttpConnection.HTTP_FORBIDDEN);
}
data[GET_STRING] = buffer.toString().trim();
break;
}
case HttpConnection.HTTP_TEMP_REDIRECT:
case HttpConnection.HTTP_MOVED_TEMP:
case HttpConnection.HTTP_MOVED_PERM: {
url = httpConnection.getHeaderField("Location");
data = doPost(url, postData, properties, returnType);
break;
}
case HttpConnection.HTTP_UNAUTHORIZED:
InputStream inputStream = httpConnection.openInputStream();
 
switch (returnType) {
case GET_STRING:
int c;
 
while ((c = inputStream.read()) != -1) {
buffer.append((char) c);
}
data[GET_STRING] = buffer.toString().trim();
inputStream.close();
break;
case GET_INPUTSTREAM:
data[GET_INPUTSTREAM] = inputStream;
break;
case GET_BYTEARRAY:
data[GET_BYTEARRAY] = null;
break;
 
}
break;
default:
data[GET_STRING] = buffer.toString().trim();
break;
}
} else {
System.out.println("httpConnection is null");
}
if ((httpConnection != null && httpConnection.getType() != null) && httpConnection.getType().trim().startsWith("text/javascript")) {
// log.debug(buffer.toString());
}
} else {
 
System.out.println("ConnectionDescriptor is null");
data = null;
}
} catch (Exception e) {
e.printStackTrace();
data = null;
 
} finally {
 
if (os != null) {
try {
os.close();
os = null;
} catch (IOException e) {
}
}
if (httpConnection != null) {
try {
httpConnection.close();
} catch (IOException e) {
}
}
 
connectionFactory = null;
httpConnection = null;
 
}
return data;
}
 
}
 
Kamalesh
Please use plain text.
Contributor
ratheesh
Posts: 26
Registered: ‎07-04-2011
My Device: curve 9300
My Carrier: airtel

Re: MY App is Not working in BIS (Nigeria)

How can we  register  blackberry alliance program. I want to work the app on BIS in all countries . please help me to register ? anuy link ? steps?

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

Re: MY App is Not working in BIS (Nigeria)

Minor point.

 

The following code, which is included in the previous post, is pretty inefficient.  And assumes that the data to be returned can be treated as a String (i.e. is text) at least temporaril, so if you used this code for binary data it may not work so well.

 

// --- Inefficient code

 

int c;
while ((c = inputStream.read()) != -1) {
buffer.append((char) c);
}

 

inputStream.close();
 
switch (returnType) {
case GET_STRING:
data[GET_STRING] = new String(buffer.toString().trim().getBytes(), "UTF-8");
break;
case GET_INPUTSTREAM:
ByteArrayInputStream bais = new ByteArrayInputStream((buffer.toString().trim()).getBytes());
data[GET_INPUTSTREAM] = (InputStream) bais;
break;
case GET_BYTEARRAY:
data[GET_BYTEARRAY] = (buffer.toString().trim()).getBytes();
break;
 
}
 
// -- End of ineffiicent code
 
I recomend that you replace this code with something like:
 
byte [] responseBytes = IOUtities.streamToBytes(inputStream);
inputStream.close();
 
switch (returnType) {
case GET_STRING:
data[GET_STRING] = new String(responseBytes,"UTF-8");
break;
case GET_INPUTSTREAM:
ByteArrayInputStream bais = new ByteArrayInputStream(responseBytes);
data[GET_INPUTSTREAM] = (InputStream) bais;
break;
case GET_BYTEARRAY:
data[GET_BYTEARRAY] = responseBytes;
break;
 
}
Please use plain text.