Skip to content

Commit 1100b32

Browse files
malandr2copybara-github
authored andcommitted
Add code snippets for age treatment setting
PiperOrigin-RevId: 921641821
1 parent 5aff45e commit 1100b32

2 files changed

Lines changed: 115 additions & 0 deletions

File tree

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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+
/** Kotlin code snippets for [RequestConfiguration] in the NextGen developer guide. */
22+
private class RequestConfigurationSnippets {
23+
24+
private fun setChildAgeTreatment() {
25+
// [START set_child_age_treatment]
26+
val requestConfiguration =
27+
MobileAds.getRequestConfiguration()
28+
.toBuilder()
29+
// Indicate that ad requests should have child age treatment.
30+
.setAgeRestrictedTreatment(AgeRestrictedTreatment.CHILD)
31+
.build()
32+
MobileAds.setRequestConfiguration(requestConfiguration)
33+
// [END set_child_age_treatment]
34+
}
35+
36+
private fun setTeenAgeTreatment() {
37+
// [START set_teen_age_treatment]
38+
val requestConfiguration =
39+
MobileAds.getRequestConfiguration()
40+
.toBuilder()
41+
// Indicate that ad requests should have teenage treatment.
42+
.setAgeRestrictedTreatment(AgeRestrictedTreatment.TEEN)
43+
.build()
44+
MobileAds.setRequestConfiguration(requestConfiguration)
45+
// [END set_teen_age_treatment]
46+
}
47+
48+
private fun setUnspecifiedAgeTreatment() {
49+
// [START set_unspecified_age_treatment]
50+
val requestConfiguration =
51+
MobileAds.getRequestConfiguration()
52+
.toBuilder()
53+
// Indicate that ad requests should have unspecified age treatment.
54+
.setAgeRestrictedTreatment(AgeRestrictedTreatment.UNSPECIFIED)
55+
.build()
56+
MobileAds.setRequestConfiguration(requestConfiguration)
57+
// [END set_unspecified_age_treatment]
58+
}
59+
}

0 commit comments

Comments
 (0)