Open In App

How to Use Advertisement ID in Android?

Last Updated : 26 Jan, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

This article is about adding the newly introduced advertisement ID in android 13. Moving forward to further iterations of the android versions you will need to update this, otherwise, your app won’t work with the new advertisement policy.

What is an Advertisement and what it does do?

At large, it is always a great practice for all Android apps to use user-resettable IDs in order to ensure user privacy. An advertising ID is one such identifier that specifically identifies a specific user for advertising use cases like ad personalization.

You can use the Advertising ID library to enable a uniform ad-tracking solution across all devices running your app. This library defines an interface to communicate with system-level ad providers and is accessible on devices running Android 4.0 (API level 14) and higher. Your app can get consistent advertising ID values using this interface.

How to add an Advertisement ID to my Android Application?

Adding an advertisement ID to your android app is fairly easy and requires no hard steps, all you need to do is simply add up a new line in your app’s manifest that will let the Android System know that you are targeting the newer Advertisement ID and that’s it, the system will do the rest of the part to manage the AD-ID and the other background stuff.

Step #1: You need to add this line to your app’s manifest

<uses-permission android:name="com.google.android.gms.permission.AD_ID"/>

After adding this line the newer manifest would start to look somewhat like this:

<manifest ...>
<!-- This is applicable for all apps beyond the Android 13 framework-->
    <uses-permission android:name="com.google.android.gms.permission.AD_ID"/>
</manifest>

See how the permission is auto-adapted in the new system itself.

Step #2: Add the Dependencies in your Gradle file to add the support for Advertisement ID

You may need to check if you have the support for Advertisement ID, otherwise, you will need to add the below lines, and then sync the changes so that Android Studio can download the required files to add:

dependencies {
    //Add this line to add support for the advert ID
    //Note that the support is in alpha, you can change the channel to normal.
    implementation 'androidx.ads:ads-identifier:1.0.1-alpha01'
}

What about core advertisement ID?

The Google Play services’ advertising ID is a distinct ID that can be reset by the user. It gives customers better control while giving developers a straightforward, industry-standard method to keep earning money from their apps. It enables users to opt out of tailored advertisements (formerly known as interest-based adverts) within Google Play apps or reset their identifier.

Some SDKs may already indicate this permission in the SDK’s library manifest, such as the Google Mobile Ads SDK (play-services-ads). Even if you don’t explicitly specify the permission in your app’s main manifest, the AD ID permission from the SDK’s library manifest will be combined with your app’s main manifest if your app uses these SDKs as dependents.

How Does the new API work?

When Google Play Services are available, it is expected that the advertising ID totally replaces any current usage of other identifiers for advertising reasons (such as the use of ANDROID ID in Settings.Secure). GetAdvertisingIdInfo will throw a GooglePlayServicesNotAvailableException in instances where Google Play Services are not available ().

All you need to do is to add another line anywhere in your Main Activity; or where you use your advertisements or the place you initialize them.

// This line comes in declaration:
public class AdvertisingIdClient extends Object

This whole process can be understood in a better way by looking at the diagram below that explains how the Advertisement Architecture works:

Image #1: Understanding the user architecture.

Image #1: Understanding the user architecture.

A device may be able to accommodate many system-level ad providers concurrently.

If the Advertising ID library notices this circumstance, it makes sure that your app always gets its data from the same source, presuming the source is still accessible. The advertising ID is kept consistent throughout this process.

Some key facts about Advertisement ID in Android 13

When Google Play Services are available:

  • It is expected that the advertising ID totally replaces any current usage of other identifiers for advertising reasons (such as the use of ANDROID ID in Settings.Secure). 
  • GetAdvertisingIdInfo will throw a GooglePlayServicesNotAvailableException in instances where Google Play Services are not available()

Conclusion

With this, your app is all ready to work with compliance with Android 13. Do remember to add this to your further updates otherwise, your advertisement won’t work with the 13+ android versions.


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads