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
Regular Contributor
Posts: 97
Registered: ‎04-19-2012
My Device: BB Torch-9800

How to check Internet Availability?

Hi All,

 

I wanted to check internet availability before calling a web service, found a code but not working. I have disconnected the wi-fi then run my simulator but it's retrun 'true' while there is no network. Please suggest me how to check internet availability. 

bool app::isNetworkAvailable() {
	qDebug()<< "Inside network check function";
QNetworkConfigurationManager netMgr;
QList<QNetworkConfiguration> mNetList = netMgr.allConfigurations(
        QNetworkConfiguration::Active);
if (mNetList.count() > 0) {
    if (netMgr.isOnline()) {
        return true;
    } else {
        return false;
    }
} else {
    return false;
}
}

 

 

Developer
Posts: 673
Registered: ‎08-09-2010
My Device: Not Specified

Re: How to check Internet Availability?

Please check 

 

https://github.com/blackberry/NDK-Samples

 

Project name :-  NetworkStatus

 

-------------------------------------------------------------------------------

 

feel free to press the like button on the right side to thank the user that helped you.

Regular Contributor
Posts: 97
Registered: ‎04-19-2012
My Device: BB Torch-9800

Re: How to check Internet Availability?

Thanks for reply, I've already checked it but didn't get bcz it's written into 'c'. Can u help me which function would i've to called.

Developer
Posts: 216
Registered: ‎09-18-2009
My Device: Z10

Re: How to check Internet Availability?

You could use QNetworkAccessManager.

 

QNetworkAccessManager manager;
if (manager.networkAccessible() == QNetworkAccessManager::Accessible) {
    // Internet available.
}

 

Regular Contributor
Posts: 97
Registered: ‎04-19-2012
My Device: BB Torch-9800

Re: How to check Internet Availability?

Thanks for reply, actually i'm testing into simulator may be that cause a problem, can i test into simulator?

Developer
Posts: 216
Registered: ‎09-18-2009
My Device: Z10

Re: How to check Internet Availability?

The solution I posted also worked for me in the simulator.

Regular Contributor
Posts: 97
Registered: ‎04-19-2012
My Device: BB Torch-9800

Re: How to check Internet Availability?

Okey, but it's alwys retrun 'true' .

Can u tell me how to disconnect network into simulator?