Get device's signal strength

Hi guys i am trying to read the device network signal strength but i am getting an error that no non-static method exists for getSignalStrength. ( i asked ChatGPT for the code)

I am attaching the script on the gameobject.

Any ideas?

thanks

using UnityEngine;
using TMPro;
using System;



public class SignalStrengthChecker : MonoBehaviour
{
    private AndroidJavaObject telephonyManager;
    public TextMeshProUGUI textSignalStrength;
    public TextMeshProUGUI textComments;
    int counter;


    public void Start()
    {
       
        textComments.text = "Starting the App...";

        try
        {
           
            // Check if the current platform is Android
            if (Application.platform == RuntimePlatform.Android)
            {
              
                // Create an instance of the AndroidJavaClass for TelephonyManager
                AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
                AndroidJavaObject currentActivity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
                telephonyManager = currentActivity.Call<AndroidJavaObject>("getSystemService", "phone");


                // Get the signal strength
                GetSignalStrength();
              
            }
            else
            {
                Debug.Log("This script is only supported on Android devices.");
                textSignalStrength.text = "This script is only supported on Android devices.";
              
            }
        }
        catch (Exception e) 
        {
            Debug.LogException(e,this);
            textComments.text = e.ToString();
          
        }


        //textComments.text = counter.ToString();
    }

    public  void GetSignalStrength()
    {
     
        // Call the corresponding method on the TelephonyManager object to get the signal strength
        int signalStrength = telephonyManager.Call<int>("getSignalStrength");

        // You can now use the signalStrength value as needed
        Debug.Log("Signal Strength: " + signalStrength);

        textSignalStrength.text = "Signal Strength: " + signalStrength.ToString();
    }
}

the error you are rncountering is related to the non static nature of the getsignalstrenght() method.in
Unity, you can only directly access static methods of AndroidJavaObject. To resolve this issue, you can modify your code as follows:

Declare the SignalStrengthChecker class as static:

public static class SignalStrengthChecker : MonoBehaviour

Remove the Start() method and replace it with a static method that you can call from another script:

public static void CheckSignalStrength(TextMeshProUGUI textSignalStrength, TextMeshProUGUI textComments)
{
    try
    {
        // Check if the current platform is Android
        if (Application.platform == RuntimePlatform.Android)
        {
            // Create an instance of the AndroidJavaClass for TelephonyManager
            AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
            AndroidJavaObject currentActivity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
            AndroidJavaObject telephonyManager = currentActivity.Call<AndroidJavaObject>("getSystemService", "phone");

            // Get the signal strength
            int signalStrength = telephonyManager.Call<int>("getSignalStrength");

            // You can now use the signalStrength value as needed
            Debug.Log("Signal Strength: " + signalStrength);

            textSignalStrength.text = "Signal Strength: " + signalStrength.ToString();
        }
        else
        {
            Debug.Log("This script is only supported on Android devices.");
            textSignalStrength.text = "This script is only supported on Android devices.";
        }
    }
    catch (Exception e)
    {
        Debug.LogException(e);
        textComments.text = e.ToString();
    }
}

Now, you can call the CheckSignalStrength() method from another script or an event handler:
SignalStrengthChecker.CheckSignalStrength(textSignalStrength, textComments);
By making the SignalStrengthChecker class static and converting the GetSignalStrength() method to a static method, you can access it without instantiating the class.
I hope my answer is helpful for you.