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
Regular Contributor
shaina123
Posts: 59
Registered: ‎03-01-2011
My Device: Not Specified
Accepted Solution

CHeck internet available Either (3g or Wifi)

I am using following code to check either net connected is through wifi or wap but also want to check if 3g. But dont know how..

 String checkNetwork(String url)
	   {
		   ServiceBook sb = ServiceBook.getSB();
		   ServiceRecord[] records = sb.findRecordsByCid("WPTCP"); 
		   String uid = null; 

		   for(int i=0; i < records.length; i++) 
		   {
		       //Search through all service records to find the 
		       //valid non-Wi-Fi and non-MMS 
		       //WAP 2.0 Gateway Service Record.
		       if (records[i].isValid() && !records[i].isDisabled()) 
		       {

		           if (records[i].getUid() != null && records[i].getUid().length() != 0) 
		           {
		               if ((records[i].getUid().toLowerCase().indexOf("wifi") == -1) &&
		                   (records[i].getUid().toLowerCase().indexOf("mms") == -1))
		               {
		                       uid = records[i].getUid(); 
		                       break;
		               }
		           } 
		       }
		   }

		   if (uid != null) 
		   {

		       //open a WAP 2 connection
		       url=url + ";ConnectionUID=" + uid;
		   }
		   else
		   {

			//   url = url + ";interface=wifi";
			   url = url + ";deviceside=true";
			   //Consider another transport or alternative action.
		   }
		   return url;
	   }

 I want to check for 3g also pls help how ?

Please use plain text.
Developer
simon_hain
Posts: 15,873
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: CHeck internet available Either (3g or Wifi)

you can check UMTS using the radiostatus.

check peters sticky code about the connection management, no need to invent the wheel again
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Regular Contributor
shaina123
Posts: 59
Registered: ‎03-01-2011
My Device: Not Specified

Re: CHeck internet available Either (3g or Wifi)

I am using following code to check on device which network is currently working (Currently Wifi is on)

wafs=RadioInfo.getActiveWAFs();
			if ((wafs & RadioInfo.WAF_3GPP) != 0 )
			{
			
			   System.out.println("3G Radio is on");
			}
			if ((wafs & RadioInfo.WAF_CDMA) != 0 )
			{
				System.out.println("CDMA Radio is on");
			}
			if ((wafs & RadioInfo.WAF_WLAN) != 0 )
			{
				System.out.println("WiFi Radio is on");
			}
			
			 else if ((wafs & RadioInfo.WAF_WLAN) != 0 )
			{
				return false;
			}
			
			else if ((wafs & RadioInfo.WAF_CDMA) != 0 )
			{
				return false;
			}
but the Wafs has 5 values and in this case its getting into two cases (wifi and 3g) pls help me 
where i m wrong

 

Please use plain text.
Developer
simon_hain
Posts: 15,873
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: CHeck internet available Either (3g or Wifi)

you can have both wifi and 3g, can't you?
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Regular Contributor
shaina123
Posts: 59
Registered: ‎03-01-2011
My Device: Not Specified

Re: CHeck internet available Either (3g or Wifi)

Yes U right

Please use plain text.