Developer Hub
SupportDashboardGuides
  • Home
  • WiFi SDK
    • Overview
    • Integrating the SDK
      • iOS
        • QuickStart
        • SDK methods
          • initC4w
          • createCustomer
          • setupCustomer
          • createWPA2EnterpriseProfile
          • createPasspointProfile
          • getCreatedWPA2EnterpriseProfiles
          • getCreatedPasspointProfiles
          • getCustomerId
          • getCustomerInfo
          • updateCustomer
          • updateCustomerInfo
          • checkIfCustomerExists
          • getListOfPolicies
          • deletePasspointProfile
          • deleteWPA2EnterpriseProfile
          • setAPIAuthParams
          • setInterlinkedC4WIMobileSDKApplications
          • getInterlinkedC4WIMobileSDKApplications
          • logout
        • Objects
          • Customer
          • CustomerDocument
          • CustomerCreateResponse
          • CustomerInfo
          • CustomerQuery
          • WPA2EnterpriseProfile
          • PasspointProfile
        • Additional features
        • Changelog
      • Android
        • QuickStart
        • SDK methods
          • initC4w
          • createCustomer
          • setupCustomer
          • createWPA2EnterpriseProfile
          • deleteWPA2EnterpriseProfile
          • createPasspointProfile
          • deletePasspointProfile
          • isPasspointSupported
          • getCustomerId
          • getCustomerInfo
          • checkIfCustomerExists
          • updateCustomer
          • updateCustomerInfo
          • getListOfPolicies
          • setAPIAuthParams
          • getCreatedWPA2EnterpriseProfiles
          • getCreatedPasspointProfile
          • setInterlinkedC4WIMobileSDKApplications
          • getInterlinkedC4WIMobileSDKApplications
          • logout
        • Objects
          • Customer
          • CustomerDocument
          • CustomerCreateResponse
          • CustomerInfo
          • CustomerQuery
          • WPA2EnterpriseProfile
          • PasspointConfiguration
        • Additional features
        • Troubleshooting
        • Changelog
      • Flutter
        • QuickStart
        • Changelog
    • User experience
    • FAQ
  • Location SDK
    • Overview
    • Integrating the SDK
      • Android
        • Quickstart
        • Project initialization
        • SDK Methods
          • Enable/Disable
          • Handling blocking issues
          • Get Device Id
          • Reset device Id
          • Locations of Interest
            • Home location
            • Work location
        • Changelog
      • iOS
        • QuickStart
        • Installation
        • Project initialization
        • SDK methods
          • Initialization
          • Enable/Disable
          • Get Device Id
          • Reset device Id
          • Locations of interest
            • Home location
            • Work location
        • Reference versions
        • Changelog iOS
      • Flutter
        • QuickStart
        • Changelog
  • Demo toolkit
    • Demo app
    • Testlab WiFi setup
  • API Reference
    • Getting started
      • Authentication
      • Contacts
      • Locations
      • Geofences
      • Devices
      • Segments
      • WiFi logs
      • Events
    • Webhooks
    • Use cases
    • Legacy APIs (v2)
  • MyApps
    • My App Intro
    • Creating Apps
      • Access Journey Apps
      • Apps for the Dasbhoard
    • MyApps APIs and SDK
      • Access Journey SDK
      • REST APIs in MyApp
      • Context APIs
    • Sample projects
      • MyApps -Js SDK boilerplate
      • Video Advertising
      • Typeform integration
      • Facebook Pixel in Acces Journey
  • Tutorials
    • Sample onboarding flow for new app users
    • Integrating WiFi SDK in Flutter apps
Powered by GitBook
On this page
  • Getting the Device ID through a Device ID listener
  • Getting the Device ID by calling an explicit class method

Was this helpful?

Export as PDF
  1. Location SDK
  2. Integrating the SDK
  3. Android
  4. SDK Methods

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.

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

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.

PreviousHandling blocking issuesNextReset device Id

Last updated 2 years ago

Was this helpful?