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
Posts: 163
Registered: ‎12-06-2012
My Device: Z10, Q10

Is it currently possible to toggle wifi state programmatically?

I can't seem to be able to change the wifi state. I can read the state of the wifi though. I saw in a previous post that this was not possible.

http://supportforums.blackberry.com/t5/Native-Development/Turn-off-Wifi-programmatically/m-p/2296363...

 

Is it still impossible?

Developer
Posts: 824
Registered: ‎10-16-2012
My Device: Red Z10

Re: Is it currently possible to toggle wifi state programmatically?

[ Edited ]

This seems to imply that it will turn the wifi on

 

https://developer.blackberry.com/native/reference/core/com.qnx.doc.wifi_service.lib_ref/topic/wifi_s...

 

I'm not sure if it will work as it says it starts it in STA mode and I have no idea what that means but It's the only thing I noticed about turning the wifi on and off

 

here's other wifi related info

Wi-Fi Service Library

 

If this doesnt do the trick I would suggest submitting a Jira ticket

 

https://www.blackberry.com/jira/secure/Dashboard.jspa

Developer
Posts: 163
Registered: ‎12-06-2012
My Device: Z10, Q10

Re: Is it currently possible to toggle wifi state programmatically?

Actually that's an enum to know the status of the wifi radio. This


http://developer.blackberry.com/native/reference/core/com.qnx.doc.wifi_service.lib_ref/topic/wifi_se...

 

Will let you change the status of the wifi. My code is

#include "WifiController.hpp"
#include <wifi/wifi_service.h>
#include "GeoNotification.hpp"
WifiController::WifiController() {}
WifiController::~WifiController() {}

int WifiController::toggleWifiState(bool state)
{
	getWifiState();
	int status = wifi_set_sta_power(state);
	if(status==WIFI_SUCCESS)
		qDebug()<<"WIFI ENABLE SUCCESS CURRENT STATE: "<<state;
	else qDebug()<<"WIFI ENABLE FAILURE CURRENT STATE: "<<state;
	return status;

}
int WifiController::getWifiState()
{
	wifi_status_t status;
	wifi_get_status(&status);
	if(status == WIFI_STATUS_BUSY)
	{
		return 2;
	}
	if(status == WIFI_STATUS_RADIO_ON)
	{
		return 1;
	}
	if(status == WIFI_STATUS_RADIO_OFF)
	{
		return 0;
	}
	return 0;
}

 

I call the toggleWifiState() function to change the wifi state. But it doesn't work :smileysad: I am stuck on this problem for a long time.

 

 

 

 

 

Developer
Posts: 824
Registered: ‎10-16-2012
My Device: Red Z10

Re: Is it currently possible to toggle wifi state programmatically?

That would be the code from the link I posted, appears that it does work

 

=)

Developer
Posts: 163
Registered: ‎12-06-2012
My Device: Z10, Q10

Re: Is it currently possible to toggle wifi state programmatically?

It is not working for me though :smileysad: Doesn't toggle the state. Only can give the state. What am I doing wrong here? Thanks.
Developer
Posts: 824
Registered: ‎10-16-2012
My Device: Red Z10

Re: Is it currently possible to toggle wifi state programmatically?

That would likely mean that STA mode isn't regular wifi, and your best bet would be to file a feature request ticket on jira