> For the complete documentation index, see [llms.txt](https://create.cloud4wi.ai/dev-hub/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://create.cloud4wi.ai/dev-hub/location-sdk/integrating-the-sdk/android/sdk-methods/get-device-id.md).

# Get Device Id

As soon as the SDK starts for the first time, a **Device ID** is assigned to that specific installation of your app.

> The Device ID assigned to an installation might change in case of rare events, for example if the local storage of the device gets erased.

The SDK provides two different ways to obtain the Device ID.

### Getting the Device ID through a Device ID listener

The first method to obtain the Device ID is to set a `IDeviceIdListener`, as shown in the example below. When a listener is set, the SDK immediately returns the Device ID through the `onDeviceIdAvailable()` callback if the Device ID is already available. Otherwise, it will call the callback method as soon as the ID is obtained.

> The best practice for an app that want to collect on a backend systems the Device ID assigned to each installation, is to set a `IDeviceIdListener` each time it starts. The mobile app would receive the Device ID each time and should always send it to the backend system. Then, the backend system should overwrite any previously stored value if the new received value is different.

{% tabs %}
{% tab title="Java" %}

```java
public class MainActivity extends Activity {

    private GeoUniq geoUniq;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.geoUniq = GeoUniq.getInstance(this);
        this.setDeviceIdListener();
    }

    /**
     * Sets a listener to received the ID assigned to this device
     */
    private void setDeviceIdListener(){

        this.geoUniq.setDeviceIdListener(new GeoUniq.IDeviceIdListener() {

            @Override
            public void onDeviceIdAvailable(String deviceId) {
                Log.d("GeoUniq", "Device ID received: "+deviceId);
            }
        });
    }
}
```

{% endtab %}
{% endtabs %}

### Getting the Device ID by calling an explicit class method

The second way is to call the `GeoUniq.getDeviceId()` method. This method returns the value of the Device ID if it has already been obtained or `null` if the Device ID has not been obtained yet.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://create.cloud4wi.ai/dev-hub/location-sdk/integrating-the-sdk/android/sdk-methods/get-device-id.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
