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

Native Development

Reply
Developer
Posts: 93
Registered: ‎08-18-2011
My Device: 9550
My Carrier: At&T
Accepted Solution

Check for Wi-Fi Connection?

Hi Guys,

 

I used bellow code to Check for Wi-Fi Connection

I refered follow url :http://developer.blackberry.com/cascades/files/webinars/dealing_with_data.pdf

 

    bool available = false;

    foreach(QNetworkInterface interface,QNetworkInterface::allInterfaces())
    {
    	if(interface.flags().testFlag(QNetworkInterface::IsUp) && interface.name().compare(QString("ti0")) == 0)
    	{
    		available = true;

    	}
    	    }

But it is always fail.

 

What I am missing here?

 

Thanks,

Shwarup Biswas
Developer
Posts: 76
Registered: ‎02-08-2013
My Device: z10
My Carrier: rogers

Re: Check for Wi-Fi Connection?

I managed to get your snippet of code working by changing the interface name to tiw_sta0 instead of ti0 which doesn't show up in the ifconfig interface listing.

 

Cheers,

Eric

Developer
Posts: 93
Registered: ‎08-18-2011
My Device: 9550
My Carrier: At&T

Re: Check for Wi-Fi Connection?

Hi Enaud,

 

Thanks for your reply. Still it is an open issue for me.

My requirment is to find out either device currently connected via WiFi or Mobile Network.

 

I tested by changing the interface name to tiw_sta0 instate of ti0 and tested by changing

1. Mobile Network Off and WiFi On

2. Mobile Network On and Wifi Off

 

In both test case i am getting same output.

 

"lo0" =  false 
"tiw_drv0"  = false 
"tiw_sta0" =  true 
"tiw_p2pdev0" =  true 
"tiw_p2pgrp0" =  true 
"tiw_ibss0" =  true 
"pflog0" =  true 
"lo2" =  true 
"msm0" =  true 
"msm1" =  true 
"msm2" =  true 
"msm3" =  true 
"msm4" =  true 
"bptp0" =  true 
"rndis0" =  true 

 So, I how can i determind is device currently connected via WiFi or Mobile Network?

 

Thanks,

Shwarup Biswas
Developer
Posts: 76
Registered: ‎02-08-2013
My Device: z10
My Carrier: rogers

Re: Check for Wi-Fi Connection?

You're right, using the QNetworkInterface class we're able to determine if the interface is up, and capable of connecting to an AP or down (disabled). But there isn't an obvious way to determine of the interface is actually connected to an access point.

 

So far I've has some success using this code:

bool Downloader::isWifiOnline()
{
	bool available = false;
    foreach(QNetworkInterface interface,QNetworkInterface::allInterfaces())
    {
    	if(interface.flags().testFlag(QNetworkInterface::IsUp) && interface.name().compare(QString("tiw_sta0")) == 0)
    	{
    		if (interface.addressEntries().count() > 1)
    			available = true;
    	}
	}
    return available;
}

It seems that the interface has an addressEntries count of 2 when it is connected to the access point. and less when it is not. This permits us to determine if the interface has an IP address configured, hence likely connected to an access point. There is unfortuntely the possibility that the user is manually configuring the ip address of the wireless interface which may result in a false positive.

 

For now this seems to be working, but I still have a few test scenarios to try. Hopefully others can chime in regarding how they determine if the phone is connected to an access point.

 

Cheers,

Eric

Developer
Posts: 671
Registered: ‎03-21-2012
My Device: BlackBerry PlayBook 16GB
My Carrier: Vip

Re: Check for Wi-Fi Connection?

[ Edited ]

Personally, I haven't  seen yet some Qt/Cascades code that *works* for this. Here is sample in pure native code, for Retrieving network status http://developer.blackberry.com/native/documentation/bb10/recipe_netstatus_2006484_11.html

Developer
Posts: 325
Registered: ‎10-01-2012
My Device: Dev Alpha C, Playbook 32 GB
My Carrier: BleskMobil

Re: Check for Wi-Fi Connection?

It looks like interfaces were renamed again.

 

Now it looks like WiFi on my Dev Alpha C is called 

 

bcm0

 

Does it really need so complicated to check so trivial thing like connection to WiFi?

--------------------------------------------------------------------------------------------
-- My Blackberry 10 app at http://blackberry.hubalek.net
-- My Android apps at http://android.hubalek.net