|
| 1 | +// Copyright 2026 Google LLC |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package com.example.snippets; |
| 16 | + |
| 17 | +import com.google.android.libraries.ads.mobile.sdk.MobileAds; |
| 18 | +import com.google.android.libraries.ads.mobile.sdk.common.AgeRestrictedTreatment; |
| 19 | +import com.google.android.libraries.ads.mobile.sdk.common.RequestConfiguration; |
| 20 | + |
| 21 | +/** Java code snippets for {@link RequestConfiguration} in the NextGen developer guide. */ |
| 22 | +final class RequestConfigurationSnippets { |
| 23 | + |
| 24 | + private void setChildAgeTreatment() { |
| 25 | + // [START set_child_age_treatment] |
| 26 | + RequestConfiguration requestConfiguration = |
| 27 | + MobileAds.getRequestConfiguration().toBuilder() |
| 28 | + // Indicate that ad requests should have child age treatment. |
| 29 | + .setAgeRestrictedTreatment(AgeRestrictedTreatment.CHILD) |
| 30 | + .build(); |
| 31 | + MobileAds.setRequestConfiguration(requestConfiguration); |
| 32 | + // [END set_child_age_treatment] |
| 33 | + } |
| 34 | + |
| 35 | + private void setTeenAgeTreatment() { |
| 36 | + // [START set_teen_age_treatment] |
| 37 | + RequestConfiguration requestConfiguration = |
| 38 | + MobileAds.getRequestConfiguration().toBuilder() |
| 39 | + // Indicate that ad requests should have teenage treatment. |
| 40 | + .setAgeRestrictedTreatment(AgeRestrictedTreatment.TEEN) |
| 41 | + .build(); |
| 42 | + MobileAds.setRequestConfiguration(requestConfiguration); |
| 43 | + // [END set_teen_age_treatment] |
| 44 | + } |
| 45 | + |
| 46 | + private void setUnspecifiedAgeTreatment() { |
| 47 | + // [START set_unspecified_age_treatment] |
| 48 | + RequestConfiguration requestConfiguration = |
| 49 | + MobileAds.getRequestConfiguration().toBuilder() |
| 50 | + // Indicate that ad requests should have unspecified age treatment. |
| 51 | + .setAgeRestrictedTreatment(AgeRestrictedTreatment.UNSPECIFIED) |
| 52 | + .build(); |
| 53 | + MobileAds.setRequestConfiguration(requestConfiguration); |
| 54 | + // [END set_unspecified_age_treatment] |
| 55 | + } |
| 56 | +} |
0 commit comments