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
BlackBerry Development Advisor
Posts: 15,727
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: Other network Stuff

Please start a new thread for troubleshooting type questions.  Let's leave this one for informational purposes.
Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Highlighted
Developer
Posts: 111
Registered: ‎12-16-2008
My Device: Not Specified

APN/WAP Carrier Info

Just discovered this thread, great resource, thanks Peter! Very timely since I'm working on a function that requires internet connectivity (a simple update check back to my server).

 

Wanted to add a few resources. The biggest unknown for me is how to set the Direct TCP APN or WAP gateway parameters given the carrier. I've come accross the following 2 resources which have decent lists of settings:

http://forums.pinstack.com/showthread.php?t=360

http://www.blackberryforums.com/blackberry-network/2185-blackberry-internet-msn-chat-web-telnet-tcpi...

 

However, these are a bit short of a carrier name/MNC info map and will be extremely difficult to test. It's also basically impossible to get information from users in the field... if they can't connect, they won't be able to send their configuration info! Would anyone care to share their more updated and field-tested carrier APN/WAP info mappings? I think that would be a huge help to people.

 

The other resource I've found helpful is http://deviceanywhere.com/

These guys let you test your program on live handhelds from different carriers. They all seem to be in California but Verizon, T-Mobile, AT&T and Sprint are represented. Believe me, some surprising things come up when you try your app on different carriers and OS levels. They have a free trial.

 

Hope this is useful!

Nicholas

Developer
Posts: 22
Registered: ‎09-10-2008
My Device: Not Specified

Re: What can you do in the Simulator


peter_strange wrote:

From the Simulator, you can only connect using two connection methods:

1) BES/MDS
2) Direct TCP

 

If you want to test using anything else, sorry, you can't.  To test your network code, you have to run it on a real device.

 

...

Message Edited by peter_strange on 04-08-2009 02:56 PM

 

I am doing 'Direct UDP' from an application running in the simulator (v4.6.1) directly to other computers on my network.  So I think that a #3 should be added to the above list.

 

 

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: What can you do in the Simulator

Excellent suggestion.  Thanks

 

I have updates to be made, I will add this to this and get the updates posted this week. I can't actually update posts over 24 hours old, so I have to get Mark Sohm from RIM to do it.

 

But I have a request, UDP is completely missing from this Thread because I've (sadly) never used it.  Since you are using it, would you be able to write a quick tutorial post on how to use it?  Any additional information, like why you should use it compared with Socket connection etc. would also be extremely useful.  If you add this as a reply in this Thread, then I will get Mark Sohm to add references to your Post in the bits above.  Will you have a go at this?

Developer
Posts: 22
Registered: ‎09-10-2008
My Device: Not Specified

Re: What can you do in the Simulator

I would be happy to, but I am really busy for the next couple of weeks, so I can't do it right now.

 

If you remember and I don't then feel free to send me a message in a couple of weeks reminding me.

 

Developer
Posts: 490
Registered: ‎07-16-2008
My Device: Not Specified

Re: What can you do in the Simulator

I've found an APN information. There are many APN's.

Maybe it is helpful for us.

Link : http://www.pinstack.com/carrier_settings_apn_gateway.html

 

And if list not complete, please share with us.

Developer
Posts: 1,477
Registered: ‎12-30-2008
My Device: Torch 9810

WiFi Connections..

[ Edited ]

I was about to write a post that only talks wifi .. But as soon as I started writing about it, I felt, I was not only talking wifi.. I have no clue what I'm writing, but I do something useful Smiley Happy.. Also, Sure that it talks networking!

To be simple, connecting a server that is present in the internet is very easy.. You have to append a parameter called ";interface=wifi" for your balckberry to route your connections over wifi alone..

HttpConnection conn = (HttpConnection) Connector.open(url+";interface=wifi");


However, this only tries to route your connection over wifi - I would prefer wifi than anyother connection mechanism first.. Wifi will work, even when it is marked in the Service book as isDisabled(). It is always a good practice to let the user select the connection mechanism..

The thing most developers unaware of (I was also) is that BIS-B is only available for alliance members.. When you become an alliance member and get approval for its use in an application, you are told how to do this and supplied with sample code that you can include in your application. This code comes from RIM not the carrier, BIS-B is a RIM networking connection method that is not carrier specific, however the carriers have to support it. Access to BIS-B is one of the benefits of being an Alliance member, but even if you are an Alliance member, you have to apply for BIS-B for each application you want to use it with. It is possible, without BIS-B to connect to almost any device, but BIS-B just makes it easier.

So I would suggest, If you are not an alliance member, you can forget about BIS-B .. Also, If your application is not targetted on a corporate user (who uses BES), you can forget about BES too.. I'll leave BES and BIS-B in this post ..

Well, finally what we have in hand are WiFi, WAP1.0, WAP1.1, WAP2 and Direct TCP.. WAP1.0 and WAP1.1 are similar in appearance and same in code .. I will also leave that, If you want to implement it too, there is no way of retrieving it from service book instead, you will have to get it from the user(Refer NetworkDiagnosticTool) ..

KB Articles and the video tutorials including this sticky thread talks a lot about this.. Please go thru them first.. I will give a piece of code below which will seamlessly connect through and there is a rant associated with it.. Please don't use it unless you completely understand it;

String updateConnectionSuffix()
{
if (DeviceInfo.isSimulator()) {
connSuffix = ";deviceside=true";
} else
if ( (WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED) &&
RadioInfo.areWAFsSupported(RadioInfo.WAF_WLAN)) {
connSuffix=";interface=wifi";
} else {
String uid = null;
ServiceBook sb = ServiceBook.getSB();
ServiceRecord[] records = sb.findRecordsByCid("WPTCP");
for (int i = 0; i < records.length; i++) {
if (records[i].isValid() && !records[i].isDisabled()) {
if (records[i].getUid() != null &&
records[i].getUid().length() != 0) {
if ((records[i].getCid().toLowerCase().indexOf("wptcp") != -1) &&
(records[i].getUid().toLowerCase().indexOf("wifi") == -1) &&
(records[i].getUid().toLowerCase().indexOf("mms") == -1) ) {
uid = records[i].getUid();
break;
}
}
}
}
if (uid != null) {
// WAP2 Connection
connSuffix = ";ConnectionUID="+uid;
} else {
connSuffix = ";deviceside=true";
}
}
return connSuffix
};



Where connSuffix is a static variable in the Utils class I use... The above method will be called the first time, my application want to connect the internet to get the connection suffix and the updated connSuffix is used from the second connections on..

By using the ";deviceside=true" parameter, there is no need to start MDS simulator to check the networking stuff.. However the browser in the simulator need MDS simulator to work..

I would suggest using a global listener which listens for the change in ServiceBook, if this occurs, you can call the updateConnectionSuffix method to update the connSuffix..

A sample code that does this

GlobalEventListener
/**
* Invoked when the specified global event occured.
* The eventOccurred method provides two object parameters and two integer parameters for supplying details about the event itself. The developer determines how the parameters will be used.
*
* For example, if the event corresponded to sending or receiving a mail message, the object0 parameter might specify the mail message itself, while the data0 parameter might specify the identification details of the message, such as an address value.
*
* @param guid - The GUID of the event.
* @param data0 - Integer value specifying information associated with the event.
* @param data1 - Integer value specifying information associated with the event.
* @param object0 - Object specifying information associated with the event.
* @param object1 - Object specifying information associated with the event.
*/
public void eventOccurred(long guid, int data0, int data1, Object object0, Object object1)
{
if( guid == ServiceBook.GUID_SB_ADDED ||
guid == ServiceBook.GUID_SB_CHANGED ||
guid == ServiceBook.GUID_SB_OTA_SWITCH ||
guid == ServiceBook.GUID_SB_OTA_UPDATE ||
guid == ServiceBook.GUID_SB_POLICY_CHANGED ||
guid == ServiceBook.GUID_SB_REMOVED ) {
//Now update connection suffix...
}
}



I learned most of the information that are given above, from peter and some of them are in his own words(I can change them in my words, but they are more appropriate as is) ..
Thanks peter.. Smiley Happy

Finally, Thanks a lot Andy, for updating this post..

Cheers..

Message Edited by Andy on 06-01-2009 09:04 AM
Moderator Edit: Fixed an issue in the sample code reported by marKram on page 7 of this thread.
--
Manimaran Selvan
Co-Founder, Tech Lead,
Equity Markets Research Group
Developer
Posts: 1,477
Registered: ‎12-30-2008
My Device: Torch 9810

APN settings - Extended..

[ Edited ]

Raiden wrote:

I've found an APN information. There are many APN's.

Maybe it is helpful for us.

Link : http://www.pinstack.com/carrier_settings_apn_gateway.html

 

And if list not complete, please share with us.


I found this regarding APN settings.. Might be useful for someone..
http://www.modmyi.com/wiki/index.php/Carrier_APN_Settings
Cheers.. 

 Edit: Link fix!

Message Edited by mantaker on 05-26-2009 06:25 PM
--
Manimaran Selvan
Co-Founder, Tech Lead,
Equity Markets Research Group
Developer
Posts: 304
Registered: ‎08-01-2008
My Device: Not Specified

Code Sample for Http Connection

[ Edited ]

Here is some production code that I use for http connections when I am really desperate to connect by any means. I have never used WAP or WAP2 so this is not complete I guess, but it works for 99% of the cases. Works for both GET and POST requests.

 

Though COVERAGE_BIS_B is not documented in 4.2 - 4.5, and COVERAGE_CARRIER is not documented in 4.5+, having been replaced by COVERAGE_DIRECT, they are actually present in class, so the code should compile.

 

public static final int CONNECTION_DEFAULT = 0;
public static final int CONNECTION_BIS = 1;
public static final int CONNECTION_BES = 2;
public static final int CONNECTION_TCPIP = 3;
public static final int CONNECTION_WIFI = 4;

 

public boolean get(String url) {

service(url, null);

}

 

public boolean post(String url, URLEncodedPostData postdata) {

service(url, postdata);

}

 

private boolean service(String url, URLEncodedPostData postdata) {
HttpConnection con = null;
InputStream in = null;

try {
if (CoverageInfo.isOutOfCoverage())
return false;

byte[] data = null;
if (postdata != null) {
data = postdata.getBytes();
}

// If WLAN is active, try wlan
if ((RadioInfo.getActiveWAFs() & RadioInfo.WAF_WLAN) != 0) {
try {
if (CoverageInfo.isCoverageSufficient(

CoverageInfo.COVERAGE_CARRIER,

RadioInfo.WAF_WLAN, false))
{
con = HttpUtils.makeHttpConnection(

url, new HttpHeaders(),

data, CONNECTION_WIFI);
con.getResponseCode();
}
} catch (Exception ex) {
Log.error("UP.R.WF: " + ex);
con = null;
}
}

// Otherwise try the preferred connection type.
if (con == null) {
try {
con = HttpUtils.makeHttpConnection(

url, new HttpHeaders(), data,

IOPreferences.getPreferredConnectionType());
con.getResponseCode();
} catch (Exception ex) {
Log.error("UP.R1: " + ex);
con = null;
}
}

if (con == null) {
// If preferred type doesnot work, find something else.
int ctype = getCoverageBasedConnectionType();
if (ctype >= 0) {
try {
con = HttpUtils.makeHttpConnection(url,

new HttpHeaders(), data, ctype);
con.getResponseCode();
} catch (Exception ex) {
Log.error("UP.R2: " + ex);
con = null;
}
}
}

int respcode = con.getResponseCode();

// You can handle HTTP_MOVED_* here if you want to

// We don't because we connect to our own servers

if (respcode == HttpConnection.HTTP_OK) {
in = con.openInputStream();

// Handle incoming data
handleData(con, in);

return true;
}
} catch (Exception e) {
Log.error("UP.R() : " + e);
} finally {
close(con, in);
}

return false;
}

protected abstract void handleData(HttpConnection con, InputStream in);

 

private static void close(HttpConnection con, InputStream in) {
if (in != null) {
try {
in.close();
} catch (IOException e2) {
}
}
if (con != null) {
try {
con.close();
} catch (IOException e) {
}
}
}

 

 

public static int getCoverageBasedConnectionType() {
if (CoverageInfo.isCoverageSufficient(CoverageInfoProxy.COVERAGE_CARRIER,

RadioInfo.WAF_WLAN))

{
return IOConstants.CONNECTION_WIFI;
}

if (CoverageInfo.isCoverageSufficient(CoverageInfo.COVERAGE_BIS_B)) {
return IOConstants.CONNECTION_BIS;
}

if (CoverageInfo.isCoverageSufficient(CoverageInfo.COVERAGE_MDS)) {
return IOConstants.CONNECTION_BES;
}


return IOConstants.CONNECTION_DEFAULT;
}

 

Finally the method to make the http connection

 

class HttpUtils {
public static final int CONNECTION_DEFAULT = 0;
public static final int CONNECTION_BIS = 1;
public static final int CONNECTION_BES = 2;
public static final int CONNECTION_TCPIP = 3;
public static final int CONNECTION_WIFI = 4;

/**
* This method opens a HTTP connection to the given url. The method used is
* GET or POST depending on whether postData is null or not. Only the
* provided connType is used. For example, if the connType is
* CONNECTION_BES, the connection is tried using the BES only.
* The only time provided connection type is not used is when the URL
* contains ";deviceside=".
*
* @param url
* The url to connect to.
* @param requestHeaders
* The headers in the request. May be null or empty.
* @param postData
* Data to be posted to the server. If null, the GET method used
* for the http connection.
* @param connType
* The type of transport (BES / BIS / WIFI / Default) to be used
* for opening connection.
* @return Opened HttpConnection object or null if some error occurs.
*/
public static HttpConnection makeHttpConnection(String url,

HttpHeaders requestHeaders, byte[] postData, int connType) {
HttpConnection conn = null;
OutputStream out = null;

if (StringUtilities.startsWithIgnoreCase(url, "www.")) {
url = "http://" + url;
}

try {
if (url.indexOf(";deviceside=") == -1) {
switch (connType) {
case CONNECTION_BES:
url = url + ";deviceside=false";
break;
case CONNECTION_BIS:
url = url + ";XXXXXXXXXXXXXXXX";
break;
case CONNECTION_TCPIP:
url = url + ";deviceside=true";
break;
case CONNECTION_WIFI:
url = url + ";interface=wifi";
}
}

conn = (HttpConnection) Connector.open(url);

if (requestHeaders != null) {
String referer = requestHeaders.getPropertyValue("referer");

boolean sendReferrer = true;

if (referer != null &&

StringUtilities.startsWithIgnoreCase(referer, "https:") &&

!StringUtilities.startsWithIgnoreCase(url, "https:")) {
sendReferrer = false;
}

int size = requestHeaders.size();
for (int i = 0; i < size;) {
String header = requestHeaders.getPropertyKey(i);
// remove header if needed
if (!sendReferrer && header.equals("referer")) {
requestHeaders.removeProperty(i);
--size;
continue;
}

String value = requestHeaders.getPropertyValue(i++);
if (value != null) {
conn.setRequestProperty(header, value);
}
}
}

if (postData == null) {
conn.setRequestMethod(HttpConnection.GET);
conn.setRequestProperty("User-Agent",

"Profile/MIDP-2.0 Configuration/CLDC-1.0");
} else {
conn.setRequestMethod(HttpConnection.POST);
conn.setRequestProperty(

HttpProtocolConstants.HEADER_CONTENT_LENGTH,

String.valueOf(postData.length));
conn.setRequestProperty("Content-Type",

"application/x-www-form-urlencoded");
conn.setRequestProperty("User-Agent",

"Profile/MIDP-2.0 Configuration/CLDC-1.0");

out = conn.openOutputStream();
out.write(postData);
out.flush();
}
} catch (IOException e1) {
Log.error("UTIL.HTC " + e1);
close(conn, null); // Close the connection

conn = null;
} finally {
close(null, out); // Close the output, but keep connection open
}

return conn;
}

private static void close(HttpConnection con, OutputStream out) {
if (out != null) {
try {
out.close();
} catch (IOException e2) {
}
}
if (con != null) {
try {
con.close();
} catch (IOException e) {
}
}
}
}

 

 EDIT: changed COVERAGE_DIRECT to COVERAGE_CARRIER so that the code compiles on 4.2+ JDE.

Message Edited by adwiv on 05-31-2009 11:04 AM
Developer
Posts: 490
Registered: ‎07-16-2008
My Device: Not Specified

Re: APN settings - Extended..

Hi adwiv.

 

Thanks for posting.

 

I saw your code. I thinks this code works on OS 4.6.0 or later.

Because CoverageInfo.COVERAGE_BIS_B is since JDE 4.6.0.

 

Do have a suggestion how to detect BIS_B connection on lower JDE version such as JDE 4.2.0 ?

 

Maybe it works with some little changes that leaving BIS_B connection on lower JDE.

 

What do you think about?

 

Thanks in advance.