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
Contributor
Posts: 28
Registered: ‎07-04-2013
My Device: BB, 86ABC
My Carrier: IDEA

How to check whether internet is enbled or disabled?

I need check internet is available or not before calling a service in my Application.

I used following code but its not working.

 

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

 

every time its returning false.

Can any one help me?

Thanks in advance.

QNetworkAccessManager manager;
if (manager.networkAccessible() == QNetworkAccessManager::Accessible) {
    // Internet available.
}
Developer
Posts: 180
Registered: ‎12-09-2011
My Device: 9360, BB10
My Carrier: Aircel

Re: How to check whether internet is enbled or disabled?

Highlighted
BlackBerry Development Advisor
Posts: 252
Registered: ‎08-17-2012
My Device: BlackBerry Z10 and Q10
My Carrier: Bell

Re: How to check whether internet is enbled or disabled?

[ Edited ]

Hi KishoreTalloju,

 

Here is another way to check if the device is connected to the internet: 

 

	bool available = false;
	QNetworkConfigurationManager netMgr;
	QList<QNetworkConfiguration> mNetList = netMgr.allConfigurations(QNetworkConfiguration::Active);
	if (mNetList.count() > 0) {
		if (netMgr.isOnline()) {
			available = true;
			qDebug()<< "internet available";
		}
	}

 

 

@SamarAbdelsayed

Did this answer your question? Please accept post as solution.
Please refrain from posting new questions in solved threads.
Found a bug? Report it using the Issue Tracker
Developer
Posts: 109
Registered: ‎08-23-2012
My Device: Blackberry Z10
My Carrier: TATA DOCOMO

Re: How to check whether internet is enbled or disabled?

Hi 

bool available = false;
QNetworkConfigurationManager netMgr;
QList<QNetworkConfiguration> mNetList = netMgr.allConfigurations(QNetworkConfiguration::Active);
if (mNetList.count() > 0) {
if (netMgr.isOnline()) {
available = true;
qDebug()<< "internet available";
}
}
qDebug()<< "internet availablity :"<<available;

 

I tried that code but every time I got false. Please suggest.

Dharmender Singh
Contributor
Posts: 28
Registered: ‎06-17-2013
My Device: Z10
My Carrier: Bell

Re: How to check whether internet is enbled or disabled?

Do you use anything that attempts to check for internet on your main.qml or what ever you use for the front page?

 

For instance - mine tries to load an xml remotely for a listview - and i do an onerror dialog to say Please check your internet connection.

 

its a very simplistic work arround.

 

Contributor
Posts: 15
Registered: ‎08-09-2013
My Device: Developer
My Carrier: -

Re: How to check whether internet is enbled or disabled?

Try with this, this code worked to me... !

with this you can know if there some network enable to connect to internet ...!!! 

 

bool app::isNetworkAvailable()

{

   QNetworkConfigurationManager netMgr; QList<QNetworkConfiguration> mNetList = netMgr.allConfigurations(  QNetworkConfiguration::Active);

 

if (mNetList.count() > 0)

{

  if (netMgr.isOnline())

  {

       return true;

   }

   else

   {

       return false;

    }

}

else

{

     return false;

}

 

}

 

 

Enjoy it !!!!   Smiley Wink

Developer
Posts: 24
Registered: ‎05-16-2013
My Device: Developer
My Carrier: Developer

Re: How to check whether internet is enbled or disabled?

You will get correct results only when you use BPS services