Skip to content

Commit 02f4198

Browse files
nventimiglicopybara-github
authored andcommitted
Added Anchored Adaptive Banner snippets.
PiperOrigin-RevId: 794662645
1 parent fc13e69 commit 02f4198

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

samples/HelloWorld/Assets/Snippets/AdManagerBannerViewSnippets.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,5 +133,20 @@ private void HandleAppEventExample(Renderer renderer)
133133
};
134134
// [END handle_app_event_example]
135135
}
136+
137+
private void CreateAnchoredAdaptiveBannerView()
138+
{
139+
// [START create_anchored_adaptive_banner_view]
140+
// Get the device safe width in density-independent pixels.
141+
int deviceWidth = MobileAds.Utils.GetDeviceSafeWidth();
142+
143+
// Define the anchored adaptive ad size.
144+
AdSize adaptiveSize =
145+
AdSize.GetCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(deviceWidth);
146+
147+
// Create an anchored adaptive banner view.
148+
bannerView = new AdManagerBannerView(AD_UNIT_ID, adaptiveSize, AdPosition.Bottom);
149+
// [END create_anchored_adaptive_banner_view]
150+
}
136151
}
137152
}

samples/HelloWorld/Assets/Snippets/BannerViewSnippets.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ internal class BannerViewSnippets
1515
#else
1616
private const string AD_UNIT_ID = "unused";
1717
#endif
18+
19+
#if UNITY_ANDROID
20+
private const string ANCHORED_ADAPTIVE_AD_UNIT_ID = "ca-app-pub-3940256099942544/9214589741";
21+
#elif UNITY_IPHONE
22+
private const string ANCHORED_ADAPTIVE_AD_UNIT_ID = "ca-app-pub-3940256099942544/2435281174";
23+
#else
24+
private const string ANCHORED_ADAPTIVE_AD_UNIT_ID = "unused";
25+
#endif
26+
1827
BannerView bannerView;
1928

2029
private void CreateBannerView()
@@ -112,5 +121,20 @@ private void DestroyBannerView()
112121
}
113122
// [END destroy_banner_view]
114123
}
124+
125+
private void CreateAnchoredAdaptiveBannerView()
126+
{
127+
// [START create_anchored_adaptive_banner_view]
128+
// Get the device safe width in density-independent pixels.
129+
int deviceWidth = MobileAds.Utils.GetDeviceSafeWidth();
130+
131+
// Define the anchored adaptive ad size.
132+
AdSize adaptiveSize =
133+
AdSize.GetCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(deviceWidth);
134+
135+
// Create an anchored adaptive banner view.
136+
bannerView = new BannerView(ANCHORED_ADAPTIVE_AD_UNIT_ID, adaptiveSize, AdPosition.Bottom);
137+
// [END create_anchored_adaptive_banner_view]
138+
}
115139
}
116140
}

0 commit comments

Comments
 (0)