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
gpatton
Posts: 193
Registered: ‎12-29-2010
My Device: Bold 9900

How would I go about detecting a data connection?

Hello,

 

I'm loading a Map View in my app, and I'd like to display a System Dialog if the device does not have a data connection (wifi or cell). 

 

How do I go about implementing this in QML? A search in this forum showed up no results, unless I wasn't looking properly.

 

Thanks!

 

Please use plain text.
Developer
oliver_kranz
Posts: 216
Registered: ‎09-18-2009
My Device: Z10

Re: How would I go about detecting a data connection?

You have to implement this in C++ because this functionality is not supported in QML. But you can then make a C++ function Q_INVOKABLE so that you can call it from QML.

 

You can use QNetworkAccessManager.networkAccessible():

 

http://qt-project.org/doc/qt-4.8/qnetworkaccessmanager.html

 

You can give it a try but for us it did not work properly and returned wrong results. So, we are currently using the bps API.

 

#include <bps/bps.h>
#include <bps/netstatus.h>

bool netAvail = false;
netstatus_get_availability(&netAvail);
if (netAvail) {
    // Network available
} else {
    // Network not available
}

 

Please use plain text.
Developer
BojanKogoj
Posts: 76
Registered: ‎01-08-2013
My Device: Z10 LE

Re: How would I go about detecting a data connection?

[ Edited ]

It works, however I get a warning

 


'int netstatus_get_availability(bool*)' is deprecated (declared at C:/bbndk/target_10_2_0_1155/qnx6/usr/include/bps/netstatus.h:404) [-Wdeprecated-declarations]


 

Please use plain text.
Developer
oliver_kranz
Posts: 216
Registered: ‎09-18-2009
My Device: Z10

Re: How would I go about detecting a data connection?

Yes, it is deprecated. The documentation recommends to use netstatus_info_get_availability() instead.

 

This function has been deprecated - use netstatus_get_info(), netstatus_info_get_availability() and netstatus_free_info().

 

https://developer.blackberry.com/native/reference/core/com.qnx.doc.bps.lib_ref/topic/netstatus_get_a...

Please use plain text.