Languages

Menu
Sites
Language
enabling wifi in Tizen 4.0

wifi_manager_h wifi;

//callback to be called when WiFi is activated
void on_wifi_activated(wifi_manager_error_e result, void *user_data)
{
    if (result == WIFI_ERROR_NONE)
    {
            dlog_print(DLOG_INFO, LOG_TAG,"WiFi activation request successfully finished!");
        bool wifi_activated = false;
            int ret=wifi_manager_is_activated(wifi,&wifi_activated);
        if (ret== WIFI_MANAGER_ERROR_NONE)
        {
            if (wifi_activated)
            {
                dlog_print(DLOG_INFO, LOG_TAG,"status: activated!");
            }
            else
            {
                    dlog_print(DLOG_INFO, LOG_TAG,"Error! WiFi not activated!");
            }
        }else if(ret== WIFI_MANAGER_ERROR_PERMISSION_DENIED){
            dlog_print(DLOG_INFO, LOG_TAG,"WIFI_MANAGER_ERROR_PERMISSION_DENIED");
        }else if(ret== WIFI_MANAGER_ERROR_INVALID_PARAMETER){
            dlog_print(DLOG_INFO, LOG_TAG,"WIFI_MANAGER_ERROR_INVALID_PARAMETER");
        }else if(ret== WIFI_MANAGER_ERROR_OPERATION_FAILED){
            dlog_print(DLOG_INFO, LOG_TAG,"WIFI_MANAGER_ERROR_OPERATION_FAILED!");
        }else if(ret== WIFI_MANAGER_ERROR_NOT_SUPPORTED){
            dlog_print(DLOG_INFO, LOG_TAG,"WIFI_MANAGER_ERROR_NOT_SUPPORTED");
        }
        else
        {
            dlog_print(DLOG_INFO, LOG_TAG,"Error! Could not check WiFi status!");
        }
    }
    else
    {
        dlog_print(DLOG_INFO, LOG_TAG,"Error! WiFi activation failed!");
    }
}

//This simple function activates WiFi.
// It returns:
// -1 on failure,
// 0 when the WiFi activation request was successful (in that case callback will be executed),
// and 1 when WiFi has been already activated.
int activate_wifi()
{
    int result = -1;
    if (wifi_manager_initialize(&wifi) == WIFI_MANAGER_ERROR_NONE)
    {
        bool wifi_activated = false;
        if (wifi_manager_is_activated(wifi,&wifi_activated) == WIFI_MANAGER_ERROR_NONE)
        {
            if (wifi_activated)
            {
                dlog_print(DLOG_INFO, LOG_TAG,"WIFI already activated!");
                result = 1;
            }
            else
            {
                dlog_print(DLOG_INFO, LOG_TAG,"WIFI not activated!");
                if (wifi_manager_activate(wifi,on_wifi_activated, NULL)== WIFI_MANAGER_ERROR_NONE)
                {
                    dlog_print(DLOG_INFO, LOG_TAG,"WIFI activation requested! Please wait for callback");
                    result = 0;
                }
                else
                {
                    dlog_print(DLOG_INFO, LOG_TAG,"Failed to request WiFi activation!");
                    result = -1;
                }
            }
        }
        else
        {
            dlog_print(DLOG_INFO, LOG_TAG,"Could not check WiFi status!");
            result = -1;
        }
    }
    else
    {
        dlog_print(DLOG_INFO, LOG_TAG,"WiFi initialization error!");
        result = -1;
    }
    return result;
}

 

I am still getting message "Error! WiFi not activated!" . Do i need any special permissions