How I got notification of Wifi on / Off status?

Hello

My rquirement as below

-J' I need notification when the user enable or disable wifi.

I got the signal on bluetooth technology, but for wifi, I don't get any signal.

I am waiting for your positive response please reply me as soon as possible.

Take a look at this - it works for me. Everything I do is to delay the wifi control up/down status for a few seconds whenever I get a network change event to allow the interface change complete.

#include "NetworkMonitor.hpp"

NetworkMonitor* NetworkMonitor::_instance;

NetworkMonitor::NetworkMonitor(QObject *parent)
    : QObject(parent)
    , _initialised(false)
    , _networkWasAvailable(true)
    , _wifiWasAvailable(true)
    , _timer(new QTimer(this))
{
    QObject::connect(_timer, SIGNAL(timeout()),
                       this, SLOT(onTimeout()));
}

NetworkMonitor::~NetworkMonitor() {
    if (_timer->isActive())
        _timer->stop();
    QObject::disconnect(_timer, SIGNAL(timeout()),
                          this, SLOT(onTimeout()));
}

NetworkMonitor *NetworkMonitor::getInstance(QObject *parent)
{
    if (_instance == 0) {
        _instance = new NetworkMonitor(parent);
    }
    return _instance;
}

void NetworkMonitor::start() {
    initialise();
    setNetworkInitialStatus();
    setWifiInitialStatus();
}

void NetworkMonitor::stop() {
    _timer->stop();
    terminate();
}

void NetworkMonitor::initialise() {

    qDebug() << "XXXX NetworkMonitor::initialise() starting..." << endl;

    bool initialised = true;

    if (bps_initialize() == BPS_FAILURE) {
        initialised = false;
        qDebug() << "XXXX Error: BPS failed to initialise" << strerror(errno) << endl;
    }

    if (netstatus_request_events(0) == BPS_FAILURE) {
        initialised = false;
        qDebug() << "XXXX Error: Failed to request Netstatus BPS events" << strerror(errno) << endl;
        bps_shutdown();
    } else {
        qDebug() << "XXXX Registered for Netstatus BPS events OK" << endl;
        subscribe(netstatus_get_domain());
    }
    _initialised = initialised;
}

void NetworkMonitor::terminate() {
    qDebug() << "XXXX NetworkMonitor::terminate entered ..." << endl;
    netstatus_stop_events(0);
    unsubscribe(netstatus_get_domain());
    bps_shutdown();
}

void NetworkMonitor::event(bps_event_t *event) {
    qDebug() << "XXXX NetworkMonitor::event() entered ..." << endl;

    int domain = bps_event_get_domain(event);
    if ((netstatus_get_domain() == domain) &&
        (bps_event_get_code(event) == NETSTATUS_INFO)) {
            handleNetStatusEvent(event);
    }
}

void NetworkMonitor::handleNetStatusEvent(bps_event_t *event)
{
    Q_UNUSED(event)

    qDebug() << "XXXX NetworkMonitor::handleNetStatusEvent() entered ..." << endl;

    setNetworkStatus();
    if (!_timer->isActive()) {
        _timer->start(5000);
    }
}

void NetworkMonitor::onTimeout()
{
    if (_timer->isActive())
        _timer->stop();
    setWifiStatus();
}

void NetworkMonitor::setNetworkInitialStatus()
{
    if (networkAvailabile()) {
        qDebug() << "XXXX Network Initially Available" << endl;
        _networkWasAvailable = true;
        emit networkAvailable();
    } else {
        qDebug() << "XXXX Network Initially Not Available" << endl;
        _networkWasAvailable = false;
        emit networkNotAvailable();
    }
}

void NetworkMonitor::setWifiInitialStatus()
{
    if (wifiAvailabile()) {
        qDebug() << "XXXX Wifi Initially Available" << endl;
        _wifiWasAvailable = true;
        emit wifiAvailable();
    } else {
        qDebug() << "XXXX Wifi Initially Not Available" << endl;
        _wifiWasAvailable = false;
        emit wifiNotAvailable();
    }
}

void NetworkMonitor::setNetworkStatus()
{
    if (networkAvailabile()) {
        qDebug() << "XXXX Network Available" << endl;
        if (!_networkWasAvailable) {
            qDebug() << "XXXX Network changed to Available" << endl;
            _networkWasAvailable = true;
            emit networkAvailable();
        }
    } else {
        qDebug() << "XXXX Network Not Available" << endl;
        if (_networkWasAvailable) {
            qDebug() << "XXXX Network changed to Not Available" << endl;
            _networkWasAvailable = false;
            emit networkNotAvailable();
        }
    }
}

void NetworkMonitor::setWifiStatus()
{
    if (wifiAvailabile()) {
        qDebug() << "XXXX Wifi Available" << endl;
        if (!_wifiWasAvailable) {
            qDebug() << "XXXX Wifi changed to Available" << endl;
            _wifiWasAvailable = true;
            emit wifiAvailable();
        }
    } else {
        qDebug() << "XXXX Wifi Not Available" << endl;
        if (_wifiWasAvailable) {
            qDebug() << "XXXX Wifi changed to Not Available" << endl;
            _wifiWasAvailable = false;
            emit wifiNotAvailable();
        }
    }
}

bool NetworkMonitor::networkAvailabile()
{
    netstatus_info_t *info;
    bool available = false;

    if (netstatus_get_info(&info) == BPS_SUCCESS) {
        if (netstatus_info_get_availability(info)) {
            available = true;
        }
        netstatus_free_info(&info);
    }
    return available;
}

bool NetworkMonitor::wifiAvailabile()
{
    qDebug() << "XXXX NetworkMonitor::wifiAvailabile()" << endl;

    bool available = false;

    netstatus_interface_list_t iflist;
    netstatus_get_interfaces(&iflist);

    qDebug() << "XXXX NetworkMonitor::wifiAvailabile() - num_interfaces=" << iflist.num_interfaces << endl;

    for(int i = 0; i < iflist.num_interfaces; i++) {

        netstatus_interface_details_t *details = 0;
        netstatus_get_interface_details(iflist.interfaces[i], &details);

        if(details) {
            qDebug() << "XXXX NetworkMonitor::wifiAvailabile() - i/f details Available" << endl;
            const char *name = netstatus_interface_get_name(details);
            netstatus_interface_type_t type = netstatus_interface_get_type(details);

            qDebug() << "XXXX NetworkMonitor::wifiAvailabile() - i/f name=" << name << endl;
            qDebug() << "XXXX NetworkMonitor::wifiAvailabile() - i/f type=" << type << endl;
            qDebug() << "XXXX NetworkMonitor::wifiAvailabile() - is_up=" << netstatus_interface_is_up(details) << endl;

            if (type == NETSTATUS_INTERFACE_TYPE_WIFI) {
                if (netstatus_interface_is_up(details)) {
                    qDebug() << "XXXX NetworkMonitor::wifiAvailabile() - Found a WiFi i/f in UP State" << endl;
                    available = true;
                } else {
                    qDebug() << "XXXX NetworkMonitor::wifiAvailabile() - Found a Wifi i/f in DOWN State" << endl;
                }
            }
        } else {
            qDebug() << "XXXX NetworkMonitor::wifiAvailabile() - i/f details N/A" << endl;
        }
        netstatus_free_interface_details(&details);
    }
    netstatus_free_interfaces(&iflist);
    return available;
}

Tags: BlackBerry Developers

Similar Questions

  • How to disable Notification "Mobile Link is Off"

    I didn't want to make use of the link Adobe Mobile device and never even tested when I signed up for an Adobe account export to PDF, but every time I open a document, I get this reminder bubble irritating in the upper right corner that the feature is currently disabled.  It's basically a sales pitch.

    How can I disable this notification?  I went into preferences and turn off switches the appeared may affect this, but the bubble continues to display each time I open a document.

    Help!

    Irritating Acrobat Bubble.JPG

    Hi Mike,.

    Please click on this notification once and I believe that he will not haunt you again.

    Kind regards
    Rahul

  • 9.3.4's 6 iOS iPhone Wifi turns off when the phone is locked. How to solve this?

    Hey! I have a 6 - iOS 9.3.4 - 16 GB iPhone. My phone WiFi turns off eventually when I lock it... The problem is that I get no notification because of this problem. I'm too lazy to try troubleshooting for this problem, just read a lot of advice, but it had a bad feedback. How would I fix this? Thank you.

    It is not a problem. This is a design feature which is present in all iPhones and all versions of iOS for 9 years. WiFi turns off 30 seconds after the phone goes to sleep to save battery life. If you want to keep it you must connect the phone to the power.

  • HP Pavilion series g - button wifi goes off to off. There is no option to turn on.

    Product: LW259UA #ABA

    G6-1b79dx model

    Windows 7 Home Premium

    The wifi button off off.  How can I activate WiFi?

    Hi BP777,

    Welcome to the HP Forums!

    I would like to take a moment and thank you for using the forum, it's a great place to find answers. You have the best experience in the HP forum, I would like to draw your attention to the Guide of the Forums HP first time here? Learn how to publish and more.

    I understand that you are unable to activate the wireless.  Here is a link for troubleshooting your wireless network and Internet access (Windows 7). Please note step 2 of the section "impossible to connect to the Internet or wireless network".

    Have you tried to enable it in Device Manager?

    Did you run The HP Support Assistant to help find updates and solve problems.

    Have you tried MS Fix It to help solve problems running?

    There are 2 updates of bios for your system, you have those done? Here is a link to the drivers PC laptop HP Pavilion 1b79dx g6to get updates to the bios.

    Please let me know if this helped.

  • WiFi on/off button and indicator acute/severe problems in HP Pavilion dv8t-1000 CTO

    I bought a HP Pavilion dv8t-1000 CTO in December.  Within a month, a hard drive has failed and another was provided under the guarantee.

    But now there are new problems. First of all, the Treble/Bass indicator keeps popping up without reason and the bar keeps increase or decrease. Then there is the problem of Wifi. It seems that my Wifi continues to go without reason. I thought that the two issues were linked. But I'm beginning to see that my Wifi turned off only when the laptop is moved. Just the slightest movement will come out, BUT it happens every time the laptop is moved.

    I also noticed that when these problems are occurring, the 'secret' or the Wifi icon on the media smart bar (above the keyboard) will not match the icons on the screen. Twice the mute icon was red in the smart media bar, but the volume was on. Sometimes the Wifi went nuts and off, because of traffic and then the Wifi light turned back to blue on the media smart bar, but wifi is always off.

    Once both the 'secret' and wifi in the smart bar icons does not match what it says on the screen. WiFi is turned off, but the icon was blue. The speakers were on, but the silent icon was red. I activated the wifi back and the mute icon on the awesome bar, went from red to white.

    I am Windows 7 Home Premium 64 bit slot.

    Any thoughts? Ideas? I really need to fix this problem because the Wifi problem that happens at least 20 times a day.

    FOUND THE FIX! For 'problem with cursor high Pavilion dv8 (treble/ba ss control) of the bar '.

    Ryan, Manager case HP very kind & helpful to the 877-917-4380-ex93 said according to his research, this '' correction '' is a 2-step process, I just made the step 1 and appear to have solved the problem - hope it works for others!

    This is an update the: "'IDT High Definition Audio CODEC Driver -this is a self-extracting compressed file that contains the driver for Windows 7 for IDT HD audio." "

    "Correction and improvement:

    Provides a new version of driver in order to meet the criteria for Microsoft Windows Hardware Quality Labs (WHQL). »

    Go to http://www.hp.com/cgi-bin/hpsupport/index.pl

    Choose "united States (English).

    Select "Download drivers and software (and firmware)" and enter "nq226av" (if that's your product number)

    Choose the operating system (32 or 64-bit)

    Click the sign more/drop down to the left of 'Driver - Audio (1)' ((deuxieme from top)

    Click Download, save to desktop, run and restart.

    Seems to have worked for me so far! If not, the next step will be...

    Step 2 being updated the Bios on comp. including Mr. Ryan said I would need to return to a normal technical support (India) because he did not know how and apparently you can mess up your PC by doing this...
    Let me know if this worked for you!

  • HOW TO DISABLE NOTIFICATION OF "PARENTAL CONTROL IS LIT" ON A STANDARD USER ACCOUNT?

    HOW TO DISABLE NOTIFICATION OF "PARENTAL CONTROL IS LIT" ON A STANDARD USER ACCOUNT?

    Hi rafnbaf,

    You cannot disable parental controls by using the standard user account. You should be an administrator to turn on or off the parental control.
    See Set up Parental controls

    Visit our Microsoft answers feedback Forum and let us know what you think.

  • How call you notifications when new sms received?

    Hello, everyone:

    I'm developing an application on sms-blocked.

    Here's the problem: notifications (instant preview) is triggered before the message received! But how to prevent the notification when the sms is blocked in the MessageService::messageReceived slot?

    I want to change the profile of "AlertOff" mode when it is blocked received.but sms I got notification of instant preview's show before the messageReceived signal triggered. "

    How to do this? Thank you very much!

    Nobody knows who?

  • Symbol of Smartphone Wifi blackBerry on the notification with wifi bar disabled

    Hello

    Since a few days, I have a wifi symbol on my notification with 1 (number) bar on the left of the symbol.

    I have the wifi turned off, but the symbol does not disappear.

    Select the notification bar, I have only the calendar entries, appears nothing else that might be related to wifi.

    Any suggestion on what to check?

    Thanks in advance

    Ciao

    Giorgio

    Sorry,

    I should have read first entry in the forum :-(

    A removal of simple battery and then reinsert it solved the problem.

    Giorgio

  • IPad 2 Air after update to iOS10 wifi turns off automatically.

    IPad 2 Air after update to iOS10 wifi turns off automatically.

    Hello. Could you please identify your router? Also try to describe a little more when it stops, and you can reconnect after that.

  • How to disable notification of party 3rd in WatchOS3?

    I have a bunch of 3rd party applications on my phone I have notifications for it, I DON'T WANT notifications on my watch.

    I tried to turn the "mirror Iphone warns of:" tab off in the settings for notifications of shows for these applications, but it does not seem to turn off notifications. I still get notifications on my watch of Waze, BBC News, auto, etc...

    I'm doing something wrong? Is there another way to disable notifications short turn it off on the iphone?

    I have a series 1 (new) running watch OS 3 and 6s iphone running IOS 10

    Thank you

    Max

    Hey Max!

    It seems that you have already followed the right process to disable notifications. I use the same features and the following worked for me:

    Launch the Apple Watch app from the homescreen on your iPhone.

    • Tap Notifications.
    • Tap the application that you want to change.
    • Click custom, if they are available to view all settings.
    • Adjust to your taste.
  • WiFi turns off and then don't come back

    I have a new (30 days) Macbook Air, but suffers more and more the following problem: for reasons I can not determine, the Wifi turns off. When I try to turn it back on, it will not go back. The only way to let him back on is to restart the Mac. Sometimes, when I reboot, it takes a long time to restart, sometimes not. But once it restarts, Wifi is back.

    Thoughts?

    Wi - Fi is really turning itself off?

    If this is the case the icon Wi - Fi in your Mac's menu bar looks like this

    Confirms that this is what you are experiencing. If so, please contact AppleCare. Click on the Supportlink above.

  • WiFi, power off

    I have an iPad 2 Air, 128 GB running iOS 9.3.2 from time to time, 1-2 days a week, I'm having a problem where the wifi turns off suddenly during use.  Router/source is not the issue, my cell phone, Amazon Fire TV, computer, etc. are not performed.  I need to go to settings > Wi - Fi and turn manually the wifi... and some days it will be the last 5 minutes and shuts off again, duty be turned on.  Incredibly infuriating!  I have reset and restored the ipad and nothing has solved the problem.  Any help is greatly appreciated.

    Thank you!

    "I have reset.

    There is more than one type of reset so I'm not sure that one talk it to so tap Settings > general > reset > reset network settings, then reboot your iPad.

    You will need to go to settings > Wi - Fi and enter your Wi - Fi password.

    See if makes a difference.

    If not, try helping the troubleshooting provided in this article to support > If your iPhone, iPad or iPod touch connects to a Wi-Fi - Apple Support Network

    Even if other devices can access a WiFi ok, it wouldn't hurt to restart your router then try a Wi - Fi connection on your iPad.

  • If I deleted an application how can I get automated payments taken off my credit card to stop

    If I deleted an application how can I get automated payments taken off my credit card to stop

    View, change or cancel your subscription

    https://support.Apple.com/en-us/HT202039

  • Automator - how I got a file zip "with replacement"?

    Automator - how I got a file zip "with replacement"?

    I have an action that selects a folder - then creates archive in a chosen folder

    Currently - it uses the name of the source folder, and then brings new archives every time as:

    My folder.zip

    my zip 1 file

    My 2 zip. folder

    I wish there was only a single zip and the new version would ALWAYS OVERWRITE the old.

    Q: How can I get what's going on?

    or how to do that with applescript?

    Hello

    In an Automator workflow, you can use this script in "run AppleScript" action.

    ----

    on track {, parameters} - script for Automator

    -create an archive in the parent folder, it uses the name of the folder, it overwrites one archive existing and returns the path of the archive

    return fileZipper (item 1 of the entry) - entry is a list and it contains the path of the folder

    end of race

    on fileZipper (thisItem)

    tPath thisItem text value

    If tPath ends by ":" and then

    the value text delimiters oTid point

    the value point text delimiters {"": "}

    tPath the text value 1 through the text element - tPath 2

    the point text delimiters oTid value

    end if

    zip (tPath & ".zip") the value as a text file

    shell script "/ usr/bin/Ditto - c k - rsrc - keepParent" & (quoted in the form of tPath POSIX path) & "" & quoted form of POSIX zipFile path ".

    return the zip as an alias file

    end fileZipper

    -----

    This script create a new archive or overwrite an archive existing with the same name as the folder.

    The destination is the parent of the selected folder.

    If you want to move this archive to a specific folder, add "move Finder items" action after the action "Run the AppleScript.

  • How to install the USB WiFi adapter?

    I've received a USB WIFI adapter and do not know how to set up or even knowing if it is attached.

    New hardware has been installed on the plug-in. Switch turned on, but there is nothing that lets me know he's working.

    Hi garyhenrymacphail,

    Hmm and what should I say now? I also put t how to configure your USB WiFi adapter because I don t know which you have, what laptop and operating system.

    The spirit normally each USB WiFi adapter, you also get a manual how to install it. Alternative, contact the manufacture of this adapter for more information.

Maybe you are looking for

  • Acquisition &amp; savings with smart camera

    I couldn't find an example on the recording of the images of the sequence to hard drive with Ximea smart cameras. I have a RL50C smart camera. I want to acquire and store images on the hard drive. Because I don't have a LabVIEW installed in this unit

  • UNABLE TO REMOVE WINDOWS HOTMAIL ACCOUNT

    UNABLE TO REMOVE WINDOWS HOTMAIL ACCOUNT... I'm trying to remove my account Hotmail/windows live ({removed email address}). When I go to http://mail.live.com/mail/CloseAccountConfirmation.aspx and him say to close my account, he said "to close your W

  • Missing title bar in Windows 7

    My title bar on applications disappeared when it is in the original format, so I don't see the title or the restore/minimize/maximize/exit buttons. I have to point the cursor at the top of the screen, then double-click on it to get the smaller versio

  • Cannot delete the empty space of the Interior of the line of text

    I use Indesign CS3 on PC, Windows 7. I have a manuscript with 100s of hours invested. In the middle of about 5% of the pages, I have spaces unremovable (1 or 2) the text. The location is about the location in the center of the page the extremely tiny

  • VMware ESXi 5.5.0 Update 1 update 2 compatibility

    HelloI have a cluster with 3 hosts running the update above 1 and I want to add a new host. Can I have three hosts running update 1 and day 2?Thank youSean