AmazonUserDataClient class in combination with the TestContentProvider class, which serves mock data.
Overview
To integrate the GetUserAgeData API in your app, use the following high-level steps:- If testing with mock data, register the
TestContentProviderclass in the Android manifest of the app that you’re using to test. - Create a simple Java object to hold the user age data.
- Create a helper class that models the extracted user age data from the Java object.
- Implement the
AmazonUserDataClientclass to query for user age data. - Call the
AmazonUserDataClientclass from your app where you’ll add logic to handle the response.
For testing
In the version of theAmazonUserDataClient class that you use for testing:
- Set the
AUTHORITYstring toamzn_test_appstore - Set the
PATHstring to/getUserAgeData?testOption=k(wherekis a number from 1 to 11)
TestContentProvider class provided on this page returns mock response combinations based on the actual response structure of the GetUserAgeData API. To test the functionality, pass a value from 1 to 11 in the testOption query parameter. The TestContentProvider class returns a response that corresponds to the value of the testOption parameter. For a list of the available mock responses provided, see Test data responses.
For production
For production, omit theTestContentProvider class and its manifest registration, and point your app to the production GetUserAgeData API.
To use the production GetUserAgeData API, in the AmazonUserDataClient class:
- Set the
AUTHORITYstring toamzn_appstore - Set the
PATHstring to/getUserAgeData
null, Exception, or FEATURE_NOT_SUPPORTED.
AmazonUserDataClient
The following is example code that calls the mocked GetUserAgeData API from your app.UserAgeDataResponse
In theAmazonUserDataClient class, you can use the following helper class that models the user age data that you extract. The example code in the AmazonUserDataClient section uses this helper class.
TestContentProvider
The following implementations are completely standalone and don’t interact with Amazon Appstore. Use this class only for early development, unit tests, or testing purposes. It is neither intended for full stack integration tests nor for production usage. With the implementation of theTestContentProvider class, you can simulate the behavior of the actual GetUserAgeData API. In either a new app, a test app, or as test logic in your actual app, use the TestContentProvider class to get the mocked response.
For details on the GetUserAgeData API response, see GetUserAgeData API.
Test data responses
The following table lists the ten mock responses returned from the TestContentProvider API as written in the previous section.testOption is a query parameter used only in the mock user data query to serve the following predefined responses.
| testOption value | Use case | Response data |
|---|---|---|
| 1 | Response for user who is 18+ years old and who’s age is verified. | |
| 2 | Response for any user where age verification and consent isn’t ascertainable. | |
| 3 | Response for a user between the ages of 0 to 12 (inclusive). | |
| 4 | Response for a user between the ages of 13 to 15 (inclusive). | |
| 5 | Response for a user between the ages of 16 to 17 (inclusive). | |
| 6 | Response for a user who is under 18 years old where consent is pending, or where consent isn’t granted. | |
| 7 | Response for any scenario where age verification law isn’t applicable. | |
| 8 | Response for when the API returns APP_NOT_OWNED status. | |
| 9 | Response for when the API returns INTERNAL_TRANSIENT_ERROR status. | |
| 10 | Response for when the API returns INTERNAL_ERROR status. | |
| 11 | Response for when the API returns FEATURE_NOT_SUPPORTED status. |
Register the TestContentProvider class in your Android manifest
To use theTestContentProvider class, you must register it in your AndroidManifest.xml file. Only the app that is going to serve you the TestContentProvider API logic, such as a test app, requires this registration step. Change the android:name attribute in the provider element to match the fully qualified class name of your TestContentProvider class.
Access the user data provided by Amazon in your app
The following code shows how to get the user data provided through theAmazonUserDataClient class. Use this code in your app where you’ll add logic to handle user age verification status and user age ranges.

