We use essential cookies for the website to function, as well as analytics cookies for analyzing and creating statistics of the website performance. To agree to the use of analytics cookies, click "Accept All". You can manage your preferences at any time by clicking "Cookie Settings" on the footer. More Information.

Only Essential Cookies
Accept All

ODID

Overview

Open Device Identifier (ODID): a developer-level non-permanent device identifier provided by Push Kit. A developer can be an enterprise or individual developer registered on HUAWEI Developers.

Example: dff3cdfd-7beb-1e7d-fdf7-1dbfddd7d30c

An ODID will be regenerated in the following scenarios:

  • Restore a phone to its factory settings.
  • Uninstall and reinstall all apps of one developer on one device.
  • Uninstall and reinstall HMS Core (APK).

An ODID is generated based on the following rules:

  • For apps from the same developer, which are running on the same device, they have the same ODID.
  • For apps from different developers, which are running on the same device, each of them has its own ODID.
  • For apps from the same developer, which are running on different devices, each of them has its own ODID.
  • For apps from different developers, which are running on different devices, each of them has its own ODID.

Use Cases

  • Device identification

    The ODIDs for multiple apps of the same developer on the same device are the same and can be used as the unique identifier of a device.

  • Data report

    When multiple apps of the same developer report data, the ODIDs in the data indicate the relationships between the apps.

NOTE

The version of HMS Core (APK) must be 5.0.2.300 or later.

Preparations

To release your app on HUAWEI AppGallery, make necessary preparations by referring to Preparations. To obtain the ODID but not to release your app on HUAWEI AppGallery, you only need to integrate the OpenDevice SDK.

Configuring the Maven Repository Address for the HMS Core SDK

The procedure for configuring the Maven repository address in Android Studio is different for Gradle plugin earlier than 7.0, Gradle plugin 7.0, and Gradle plugin 7.1 or later. Click a relevant link below to find the configuration procedure for the specific Gradle plugin version.

NOTE

The Maven repository address cannot be accessed from a browser. It can only be configured in the IDE. If there are multiple Maven repositories, add the Maven repository address of Huawei as the last one.

  • Gradle plugin earlier than 7.0
    1. Open the build.gradle file in the root directory of your Android Studio project.

    2. Add the AppGallery Connect plugin and the Maven repository.
      • Go to buildscript > repositories and configure the Maven repository address for the HMS Core SDK.
      • Go to allprojects > repositories and configure the Maven repository address for the HMS Core SDK.
      • If the agconnect-services.json file has been added to the app, go to buildscript > dependencies and add the AppGallery Connect plugin configuration.
      buildscript {
          repositories {
              google()
              jcenter()
              // Configure the Maven repository address for the HMS Core SDK.
              maven {url 'https://developer.huawei.com/repo/'}
          }
          dependencies {
              ...
              // Add the AppGallery Connect plugin configuration. Please refer to AppGallery Connect Plugin Dependency to select a proper plugin version. 
              classpath 'com.huawei.agconnect:agcp:1.6.0.300'
          }
      }
      
      allprojects {
          repositories {
              google()
              jcenter()
              // Configure the Maven repository address for the HMS Core SDK.
              maven {url 'https://developer.huawei.com/repo/'}
          }
      } 
  • Gradle plugin 7.0
    1. Open the build.gradle file in the root directory of your Android Studio project.

    2. Add the AppGallery Connect plugin and the Maven repository.
      • Go to buildscript > repositories and configure the Maven repository address for the HMS Core SDK.
      • If the agconnect-services.json file has been added to the app, go to buildscript > dependencies and add the AppGallery Connect plugin configuration and Android Gradle plugin configuration.
      buildscript {
          repositories {
              google()
              jcenter()
              // Configure the Maven repository address for the HMS Core SDK.
              maven {url 'https://developer.huawei.com/repo/'}
          }
          dependencies {
              ...
              // Add the Android Gradle plugin configuration. You need to replace {version} with the actual Gradle plugin version, for example, 7.0.1.
              classpath 'com.android.tools.build:gradle:{version}'
              // Add the AppGallery Connect plugin configuration. Please refer to AppGallery Connect Plugin Dependency to select a proper plugin version. 
              classpath 'com.huawei.agconnect:agcp:1.6.0.300'
          }
      }
    3. Open the project-level settings.gradle file and configure the Maven repository address for the HMS Core SDK.
      dependencyResolutionManagement {
          ...
          repositories {
              google()
              jcenter() 
              // Configure the Maven repository address for the HMS Core SDK.
              maven {url 'https://developer.huawei.com/repo/'}
          }
      }
  • Gradle plugin 7.1 or later
    1. Open the build.gradle file in the root directory of your Android Studio project.

    2. If the agconnect-services.json file has been added to the app, go to buildscript > dependencies and add the AppGallery Connect plugin configuration and Android Gradle plugin configuration.
      buildscript {
          dependencies {
              ...
              // Add the Android Gradle plugin configuration. You need to replace {version} with the actual Gradle plugin version, for example, 7.1.1.
              classpath 'com.android.tools.build:gradle:{version}'
              // Add the AppGallery Connect plugin configuration. Please refer to AppGallery Connect Plugin Dependency to select a proper plugin version. 
              classpath 'com.huawei.agconnect:agcp:1.6.0.300'
          }
      }
    3. Open the project-level settings.gradle file and configure the Maven repository address for the HMS Core SDK.
      pluginManagement {
          repositories {
              gradlePluginPortal()
              google()
              mavenCentral()
              // Configure the Maven repository address for the HMS Core SDK.
              maven { url 'https://developer.huawei.com/repo/' }
          }
      }
      dependencyResolutionManagement {
          ...
          repositories {
              google()
              mavenCentral()
              // Configure the Maven repository address for the HMS Core SDK.
              maven { url 'https://developer.huawei.com/repo/' }
          }
      }

Adding Build Dependencies

  1. Open the app-level build.gradle file of your project.

  2. Add build dependencies in the dependencies block.
    dependencies {
        implementation 'com.huawei.hms:opendevice:6.7.0.300'
    }
  3. Add the AppGallery Connect plugin configuration in either of the following methods:
    • Method 1: Add the following configuration under the declaration in the file header:
      apply plugin: 'com.huawei.agconnect'
    • Method 2: Add the plugin configuration in the plugins block.
      plugins {
          id 'com.android.application'
          // Add the following configuration:
          id 'com.huawei.agconnect'
      }

Obtaining the ODID

Call the OpenDeviceClient.getOdid() method to obtain the ODID.

Java
Kotlin
// Call the getOdid method to obtain the ODID.
Task<OdidResult> idResult = OpenDevice.getOpenDeviceClient(getApplicationContext()).getOdid();

// Add a listener.
idResult.addOnSuccessListener(new OnSuccessListener<OdidResult>() {
     @Override
     public void onSuccess(OdidResult odidResult) {
            String odid = odidResult.getId();
            Log.d("TAG", "getODID successfully, the ODID is " + odid );
     }
}).addOnFailureListener(new OnFailureListener() {
     @Override
     public void onFailure(Exception myException) {
        Log.d("TAG", "getODID failed, catch exception : " + myException);
     }
});
// Call the getOdid method to obtain the ODID.
val idResult = OpenDevice.getOpenDeviceClient(this).odid

// Add a listener.
idResult.addOnSuccessListener{ odidResult ->     
    Log.d("TAG", "getODID successfully, the ODID is " + odidResult.getId() )
}.addOnFailureListener{ myException ->
    Log.d("TAG", "getODID failed, catch exception : $myException")
}
Search
Enter a keyword.