Qt + Android and WiFi
-
wrote on 19 Feb 2016, 20:18 last edited by
Hello,
I am writing an app for an android device and i am wondering if it is possible to enable and disable the Wifi within my app?
Best regards
-
Hi and welcome to devnet,
I haven't tested that with Android but the Bearer Manager might be what your are looking for.
Hope it helps
-
wrote on 20 Feb 2016, 10:18 last edited by
Hi,
Yes, i read the article. When i run
QNetworkConfigurationManager manager; const bool canStartIAP = (manager.capabilities() & QNetworkConfigurationManager::CanStartAndStopInterfaces);
canStartIAP is false. My app has all permissions to edit the wifi state.
Furthermore, wheni try the following code:QNetworkConfigurationManager ncm; QList<QNetworkConfiguration> nc = ncm.allConfigurations(); foreach( QNetworkConfiguration item, nc ) { if (item.bearerType() == QNetworkConfiguration::BearerWLAN) { qDebug() << "Wifi" << item.name(); qDebug() << "state" << item.state(); } }
then i see that my app knows that there exist a mobile and wifi network but the state is alway 0x2.
I am also able to use androidextras to run java code and use the wifimanager to switch on wifi (which works), but it would be nicer to use Qt-Code only...Best regards
-
From a quick look at the code, it seams that changing the connection state is currently not supported so you are on the correct track using the QtAndroidExtras module
-
wrote on 22 Feb 2016, 15:50 last edited by
Thanks for your advice.
I've got one more question:On my Android device the QNetworkConfigurationManager only lists "Mobile" and "Wifi" but not the names of the available WLANs. Does this have to be done externally as well?
-
Did you call QNetworkConfigurationManager::updateConfigurations ?
-
wrote on 24 Feb 2016, 10:49 last edited by
Yes, i did.
-
Lifetime Qt Championwrote on 24 Feb 2016, 21:46 last edited by SGaist 3 Mar 2016, 23:10
Which version of Android ?
-
wrote on 25 Feb 2016, 09:45 last edited by
My device runs android 5.1.1 and i am using Qt 5.5.1.
-
Since Qt 5.6.0 is out, can you check again with it ?