Blackberry 10 cascades - Check Internet connectivity
Asked Answered
L

4

6

I am developing an application for BB-10 using web service. In this I want to parse JSON in both the get and post methods and I want to check the Internet availability.

How can I do this?

Lundin answered 26/11, 2012 at 12:32 Comment(0)
M
5

Check the Internet Availability using the below code

bool app::isNetworkAvailable() {
    QNetworkConfigurationManager netMgr;
    QList<QNetworkConfiguration> mNetList = netMgr.allConfigurations(QNetworkConfiguration::Active);

    return (mNetList.count() > 0 && netMgr.isOnline());
}
Mcguire answered 15/12, 2012 at 13:39 Comment(4)
I run this, But I am getting "false" only. Is there any libraries I have to add. And One more thing I am unable to connect the WIFI in Blackeberry-10 simulator. Please give me any guidance regarding this.Skittish
I am testing this code on a simulator it is giving me false. Please tell how to check for the simulator ?Hysteria
This is superfluously long. This can be replaced by one line. See my answer below.Kettledrummer
I am also getting "false" always. Please let me know, if you solved thisEleen
J
1

My teacher created a qml component that shows if there is connection and what kind of connection it is (wifi, bluetooth, carrier etc). It also sends a signal when the connection status or the interface used has changed.

The code is hosted at github: https://github.com/rodrigopex/CheckInternetMicroSample

Jujube answered 28/11, 2013 at 18:43 Comment(0)
F
0

1.HPP FILE

class controller : public QObject
{
 Q_OBJECT
public:
 controller(bb::cascades::Application *app);


public Q_SLOTS:
 void sendRequest(const QString &countryID);


private Q_SLOTS:

void onFinished();

};

2.CPP FILE

void controller::sendRequest(const QString &countryID)
{

QNetworkAccessManager* networkAccessManager = new QNetworkAccessManager(this);

const QString queryUri = QString::fromLatin1("http://192.168.1.251:410/Mobile/Service1.svc/english/Category?CountryID=%1").arg(countryID);

QNetworkRequest request(queryUri);

QNetworkReply* reply = networkAccessManager->get(request);

bool ok = connect(reply, SIGNAL(finished()), this, SLOT(onFinished()));
 Q_ASSERT(ok);
 Q_UNUSED(ok);
}


void controller::onFinished()
{
 QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
 QString response;
 if (reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() == 200)
 {
 JsonDataAccess jda;
 QVariantMap map = jda.loadFromBuffer(reply->readAll()).toMap();

QVariantList addresses = map["GetCategoryResult"].toList();

foreach(QVariant var, addresses) {
 QVariantMap addressMap = var.toMap();

qDebug() << "CategoryName is " << addressMap["CategoryName"].toString();
 qDebug() << "CategoryID is " << addressMap["CategoryID"].toString();
 }
 }
 else {
 qDebug() << "Server returned code " << reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
 }
 }

SEE FULL CODE HERE----> http://supportforums.blackberry.com/t5/Native-Development/webservice-help-json/m-p/2569953/highlight/false#M46724

Frasquito answered 5/9, 2013 at 9:9 Comment(0)
L
0

1) You can check the internet available by the following method as per documentation:

bool QNetworkConfigurationManager::isOnline () const

Returns true if the system is considered to be connected to another device via an active network interface; otherwise returns false.

2) As for the json bits, you could use the json parser in Qt 5 as follows:

JSON Support in Qt

It is simple enough to bundle Qt 5 againt your application, but it will hopefully available on the platform soon.

Qt 5 on BlackBerry 10 - Beyond the Myth

Failing that, it would be very simple to backport those few classes to Qt 4.

Logician answered 28/12, 2013 at 10:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.