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


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


Reply
New Developer
Posts: 18
Registered: ‎09-11-2009
My Device: Not Specified

How to get IP address in BB

Hi All,

 

 

I am porting STUN client application ( that is written in core Java 1.5) to Blackberry device. My question is how can we get the IP address of the BB device because that address we have to pass to the STUN server to know about the NAT type.... like this --

We do the same using core java classess in existing application.As we dont have InetAddress class in BB APIs so how can we know the IP address of the device ? Looking for kind reply

 

Developer
Posts: 588
Registered: ‎05-29-2009
My Device: 9100

Re: How to get IP address in BB

You can have a look into the class RadioInfo, maybe RadioInfo.getIpAddress(int apnId) is what you are looking for...

 

Developer
Posts: 1,474
Registered: ‎04-14-2009
My Device: Not Specified

Re: How to get IP address in BB

SocketConnection, ServerSocketConnection, and UDPDatagramConnection have a getLocalAddress method that returns the IP addresses you may be interested in. Note that these addresses may be different (if different sockets are created via different IP tunnels) and may also change with time. If you want to listen for IP address changed, you need to listen for PDP-related events via RadioStatusListener.

 

Note that RadioInfo also provides you with IP addresses assigned to the various tunnels, but you first need to find out which tunnel(s) you are interested in.

New Developer
Posts: 18
Registered: ‎09-11-2009
My Device: Not Specified

Re: How to get IP address in BB

Hi,

 

thanks for replying, I got the IP address using the below code....

String ip = new String("");

 

        try{
            int cni = RadioInfo.getCurrentNetworkIndex();
            int apnId = cni + 1;   //cni is zero based
            byte[] ipaddr = RadioInfo.getIPAddress(apnId);
            for(int i = 0;i<ipaddr.length;i++){
                int temp = (ipaddr[i] & 0xff);
                if(i<3){
                    ip=ip.concat(""+temp+".");
                }
                else{
                    ip=ip.concat(""+temp);
                }
            }
            System.out.println("ipaddress "+ip);
        }catch(Exception e)

        {
               ip = null;
        }

Developer
Posts: 1,474
Registered: ‎04-14-2009
My Device: Not Specified

Re: How to get IP address in BB

The above solution is blatantly wrong. Please see http://supportforums.blackberry.com/t5/Java-Development/wifi-ip-address/m-p/374279#M70949 for further discussion.