# Obtain Signal Strength

### Overview

This guide demonstrates how to use the 'PhoneStateListener' class in Android to monitor and retrieve the signal strength of a mobile device. This is particularly useful for applications that need to track network quality or adjust functionalities based on signal strength.

### Code Snippet

{% code overflow="wrap" lineNumbers="true" %}

```java
   
    public TelephonyManager telephoneManager;
    public PhoneStateListener phoneStateListener;

    public void listenerSignal(Context context) {
        telephoneManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
				telephoneManager.listen(phoneStateListener,
       
        phoneStateListener = new PhoneStateListener() {
            @Override
            public void onServiceStateChanged(ServiceState serviceState) {
                Logger.debug("onServiceStateChanged++++");
                super.onServiceStateChanged(serviceState);
                int voiceRegState = serviceState.getVoiceRegState();
                int dataRegState = serviceState.getDataRegState();
            }


            @Override
            public void onSignalStrengthsChanged(SignalStrength signalStrength) {
                Logger.debug("onSignalStrengthsChanged++++");
                super.onSignalStrengthsChanged(signalStrength);

                int level = signalStrength.getLevel();//Call requires API level 23
                int asu = getMethod(signalStrength, "getAsuLevel");//Hide
                int dbm = getMethod(signalStrength, "getDbm");//Hide
            }


        };

        telephoneManager.listen(phoneStateListener,
        PhoneStateListener.LISTEN_SERVICE_STATE
                | PhoneStateListener.LISTEN_SIGNAL_STRENGTHS
                | PhoneStateListener.LISTEN_CALL_STATE
                | PhoneStateListener.LISTEN_DATA_CONNECTION_STATE
                | PhoneStateListener.LISTEN_DATA_ACTIVITY);

    }


    int getMethod(SignalStrength signalStrength, String name) {
        Class<?> clazz = signalStrength.getClass();
        Method method = null;
        int i = 0;
        try {
            method = clazz.getMethod(name);//getDbm
            Object result = method.invoke(signalStrength);
            i = Integer.parseInt(String.valueOf(result));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return i;
    }
```

{% endcode %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://smartpossdk.gitbook.io/cloudpossdk/faq/other-development/obtain-signal-strength.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
