0

I would like to enable/disable Wifi and Hotspot using NativeScript Angular But I could find any way for that, Give some idea to enable/disable Wifi and Hotspot.

1 Answers1

0

You can check the docs, here, they have an example on how to work with connections:

import { connectionType, getConnectionType, startMonitoring, stopMonitoring }from "tns-core-modules/connectivity";

export function onNavigatedTo(args) {
    const page = args.object;
    let connectionTypeString;

    const type = getConnectionType();

    switch (type) {
        case connectionType.none:
            console.log("No connection");
            connectionTypeString = "No Internet connectivity!";
            break;
        case connectionType.wifi:
            console.log("WiFi connection");
            connectionTypeString = "WiFI connectivity!";
            break;
        case connectionType.mobile:
            console.log("Mobile connection");
            connectionTypeString = "Mobile connectivity!";
            break;
        case connectionType.ethernet:
            console.log("Ethernet connection");
            connectionTypeString = "Ethernet connectivity!";
            break;
        case connectionType.bluetooth:
            console.log("Bluetooth connection");
            connectionTypeString = "Bluetooth connectivity!";
            break;
        default:
            break;
    }

    startMonitoring((newConnectionType) => {
        switch (newConnectionType) {
            case connectionType.none:
                console.log("Connection type changed to none.");
                break;
            case connectionType.wifi:
                console.log("Connection type changed to WiFi.");
                break;
            case connectionType.mobile:
                console.log("Connection type changed to mobile.");
                break;
            case connectionType.ethernet:
                console.log("Connection type changed to ethernet.");
                break;
            case connectionType.bluetooth:
                console.log("Connection type changed to bluetooth.");
                break;
            default:
                break;
        }
    });

    // Stoping the connection monitoring
    stopMonitoring();

    page.bindingContext = { connectionType: connectionTypeString };
}

Now hotspot is a different issue, as far as I know there is no core module to handle this, so i recommend to access the native implementation and try hard.

Check this out this question.

Aosi
  • 111
  • 2
  • 7