[F/OS] 🥅 NetworkUtilities - Some Tools To Do With Network

:computer: Introduction

An extension that provides basic information about the network connectivity of the device.

When I start making extensions, I made a Network extension, but that only supports API > 28 devices. This extension should work on all versions.

Here are some notes:

  • All blocks marked with a pushpin (:round_pushpin:) in their names in the documentation requires the FineLocation permission. To make it work, drag out a LocationSensor component from the Sensors drawer, and in the Blocks editor, the Screen should ask for the FineLocation permission when the screen initializes.

  • All blocks marked with a hammer (:hammer:) only works in the built application, since the Companion does not have relevant permissions in the Manifest.

  • You might need a 1/10 second delay to load network data.

:package: Package name: com.gordonlu.networkutilities

:clock6: Version: 1

:date: Release date: 2022-04-26T10:30:00Z

:warning: WARNING! This extension is currently still under testing. I am not sure if this works on all devices. If you find any bugs, directly reply below. Thank you!

:open_book: Documentation

Method blocks

DisableBluetooth

image

Turns off Bluetooth without user interaction.

EnableBluetooth

image

Turns on Bluetooth without user interaction.

GetIpAddress

image

Returns the IP address of the network.

Returns: text

Parameters: useIpV4 = boolean

Is5GHzSupported

image

Return whether this adapter supports 5 GHz band.

Returns: boolean

IsBluetoothConnected

image

Checks if Bluetooth is on.

Returns: boolean

IsMobileConnection

image

Returns true if connection is through mobile connection. If WiFi and mobile is connected, this will return false.

Returns: boolean

IsRoaming

image

Returns true if the device is using roaming.

Returns: boolean

IsWiFiConnection

image

Returns true if the connection is through WiFi. If WiFi and mobile is connected, this will return true.

Returns: boolean

WifiBssid :round_pushpin:

image

Return the basic service set identifier (BSSID) of the current access point.

Returns: text

WifiFrequency

image

Returns the current frequency in MHz.

Returns: number (int)

WifiLinkSpeed

image

Returns the current WiFi link speed in Mbps.

Returns: number (int)

WifiMacAddress :round_pushpin:

image

Returns the MAC address used in this WiFi connection.

Returns: text

WifiSignalStrength

image

Returns the received WiFi signal strength indicator of the current 802.11 network, in dBm.

Returns: number (int)

WifiSsid :round_pushpin:

image

Returns the service set identifier (SSID) of the current 802.11 network.

Returns: number (int)

:jigsaw: Sample blocks

:inbox_tray: Downloads

AIX:
com.gordonlu.networkutilities.aix (11.0 KB)

JAVA: (V1)
NetworkUtilities.txt (7.2 KB)


Made with Niotron IDE.

Kindly :email: PM me if you have any questions! Also, if you like my extension, please :heart: like it! It takes some effort for me to make it...

Likes tell me the general user feedback of my extension. If you read this extension, please take 20 seconds to drop by and give a like!

If you have any features that you want to add and you know the code, PM me or directly reply below using the image button.

If you find any :lady_beetle: bugs, please reply below.


Gordon Lu

:speech_balloon: Message :earth_africa: Website

11 Likes

:chocolate_bar: Version 2!

New blocks:

GetIpAddress

image

Returns the IP address of the network.

Returns: text

Parameters: useIpV4 = boolean

WifiFrequency

image

Returns the current frequency in MHz.

Returns: number (int)

WifiMacAddress :round_pushpin:

image

Returns the MAC address used in this WiFi connection.

Returns: text

5 Likes

Di mana saya bisa ambil yang baru

Versi 2 link download?

Thanks for reminding and sorry for the delay, uploading it now.

EDIT: Uploaded it now.

ok i will wait

Already uploaded, no need to wait. :slightly_smiling_face:

1 Like

is it in the old download link?

No Rommi, I replaced the old download link. Refresh your browser and check it again.

can you give an example of block get ip address

Please add wifi enable and disable function.

Already available in this extension by Taifun. Please search first.

This extension not working.

Did you read this?

Hello Gordon,
remember me long time no talk
anyways I've been looking for an extension that can track mobile data usage, I haven't found anything, I hope you can add that. And also wifi usage, turn wifi on, off.
Thank you,
Joshua

Already asked ...

I don't think it makes sense to do many similar extensions. Therefore, if you wish, you can add this code to your extension. Some methods that may come in handy. Data usage is counted from the last time the phone was turned on. Download and upload speed shows in KB/s, data volume in Bytes.

public class DataUsageMonitor extends AndroidNonvisibleComponent {
    private long mStartRX, mStartTX;
    private Handler mHandler;
    private Runnable mRunnable;

    public DataUsageMonitor(ComponentContainer container) {
        super(container.$form());
        mHandler = new Handler();
        startMonitoring();
    }

    public void startMonitoring() {
        mStartRX = TrafficStats.getTotalRxBytes();
        mStartTX = TrafficStats.getTotalTxBytes();
        mRunnable = new Runnable() {
            @Override
            public void run() {
                long rxBytes = TrafficStats.getTotalRxBytes() - mStartRX;
                long txBytes = TrafficStats.getTotalTxBytes() - mStartTX;
                double rxSpeed = rxBytes / 1024.0;
                double txSpeed = txBytes / 1024.0;
                Monitoring(rxSpeed, txSpeed);
                mStartRX = TrafficStats.getTotalRxBytes();
                mStartTX = TrafficStats.getTotalTxBytes();
                mHandler.postDelayed(this, 1000);
            }
        };
        mHandler.postDelayed(mRunnable, 1000);
    }

    @SimpleEvent(description = "")
    public void Monitoring(double rxSpeed, double txSpeed) {
        EventDispatcher.dispatchEvent(this, "Monitoring", rxSpeed, txSpeed);
    }

    @SimpleProperty(description = "")
    public long TotalRxUsage() {
        return TrafficStats.getTotalRxBytes();
    }

    @SimpleProperty(description = "")
    public long TotalTxUsage() {
        return TrafficStats.getTotalTxBytes();
    }

    @SimpleProperty(description = "")
    public long MobileRxUsage() {
        return TrafficStats.getMobileRxBytes();
    }

    @SimpleProperty(description = "")
    public long MobileTxUsage() {
        return TrafficStats.getMobileTxBytes();
    }

Permission required:

android.permission.ACCESS_NETWORK_STATE

Import:

import android.net.TrafficStats;
import android.os.Handler;
1 Like

Hi Joshua. Did you ever find a way of tracking mobile data usage?
Many thanks.
Nigel

You can see if this is enough:

1 Like

Hi Patryk. Many thanks for your quick answer. I will have a look at this and see if I can use it somehow. My phone shows data used since my last billing period and I would like my app to tap into that so it can then roughly calculate what the balance of my data allowance is, so I can see through the app if the balance is getting low.