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
New Developer
Posts: 104
Registered: ‎09-25-2013
My Device: BB 10

BB 10 Cascades Internet Check

I need to check the Internet Connection If I get Socket Error. I am proceeding like this,

 

void Client::socketError(QAbstractSocket::SocketError socketError) {
HttpPost("https://www.google.co.in/");
}

void Client::HttpPost(QString URL ){
QNetworkRequest request = QNetworkRequest();
request.setUrl(QUrl(URL));
QNetworkAccessManager *mNetworkAccessManager = new QNetworkAccessManager(this);

bool result=connect(mNetworkAccessManager, SIGNAL(finished(QNetworkReply*)),
        this, SLOT(HttpResponse(QNetworkReply *)));

//qDebug() << result;
mNetworkAccessManager->get(request);
//printf("::: Request made to Service :::");
qDebug() << "::: Client.cpp  Request made to Service :::";
}

void Client::HttpResponse(QNetworkReply* reply) {

if (reply->error() == QNetworkReply::NoError) {
    qDebug() << "\n  Internet Ok **********";
} else {

    qDebug() << "\n No Internet **********" << reply->errorString();
    showDialog("No Inernet");
}
}

 and I am connecting to Signals and Slots like

connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this,
        SLOT(socketError(QAbstractSocket::SocketError)));

 

But some times I am getting "No Internet Dialog " Even If wi-fi Is Available. Why ?

any Problem in my code?

Please Help, Thanks !!!

 

Developer
Posts: 986
Registered: ‎03-20-2013
My Device: Red LE Developer Z10

Re: BB 10 Cascades Internet Check

Try this...

 

#include <bps/netstatus.h>

bool isConnected() {
    bool retVal = false;
    char* interface;

    if ( BPS_SUCCESS == netstatus_get_default_interface( &interface ) ) {
        netstatus_interface_details_t* details = NULL;
        if ( BPS_SUCCESS == netstatus_get_interface_details( interface, &details ) ) {
            switch ( netstatus_interface_get_type( details ) ) {
                case NETSTATUS_INTERFACE_TYPE_WIFI;
                case NETSTATUS_INTERFACE_TYPE_CELLULAR:
                    retVal = true;
            }
            netstatus_free_interface_details( &details );
        }
        bps_free( interface );
    }

    return retVal;
}

 



Developer of Built for BlackBerry certified multiFEED RSS/Atom feed reader and aggregator.  multiFEED Icon

Play nice: Clicking Like Button on posts that helped you not only encourages others to continue sharing their experience, but also improves your own rating on this board. Also, don't forget to accept a post if it solves your problem or answers your question.