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();
}
}