Skip to content

Commit eb8303a

Browse files
ericleichcopybara-github
authored andcommitted
Add includecode snippets for Android adaptive banner getAdSize
PiperOrigin-RevId: 697991795
1 parent d5b16e0 commit eb8303a

File tree

4 files changed

+10
-0
lines changed
  • java
    • admanager/BannerExample/app/src/main/java/com/google/android/gms/example/bannerexample
    • admob/BannerExample/app/src/main/java/com/google/android/gms/example/bannerexample
  • kotlin
    • admanager/BannerExample/app/src/main/kotlin/com/google/android/gms/example/bannerexample
    • admob/BannerExample/app/src/main/java/com/google/android/gms/example/bannerexample

4 files changed

+10
-0
lines changed

java/admanager/BannerExample/app/src/main/java/com/google/android/gms/example/bannerexample/MyActivity.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ private void initializeMobileAdsSdk() {
204204
.start();
205205
}
206206

207+
// [START get_ad_size]
207208
// Get the ad size with screen width.
208209
public AdSize getAdSize() {
209210
DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
@@ -218,4 +219,5 @@ public AdSize getAdSize() {
218219
int adWidth = (int) (adWidthPixels / density);
219220
return AdSize.getCurrentOrientationAnchoredAdaptiveBannerAdSize(this, adWidth);
220221
}
222+
// [END get_ad_size]
221223
}

java/admob/BannerExample/app/src/main/java/com/google/android/gms/example/bannerexample/MyActivity.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ private void initializeMobileAdsSdk() {
213213

214214
// [END request_ads]
215215

216+
// [START get_ad_size]
216217
// Get the ad size with screen width.
217218
public AdSize getAdSize() {
218219
DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
@@ -227,4 +228,5 @@ public AdSize getAdSize() {
227228
int adWidth = (int) (adWidthPixels / density);
228229
return AdSize.getCurrentOrientationAnchoredAdaptiveBannerAdSize(this, adWidth);
229230
}
231+
// [END get_ad_size]
230232
}

kotlin/admanager/BannerExample/app/src/main/kotlin/com/google/android/gms/example/bannerexample/MyActivity.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class MyActivity : AppCompatActivity() {
4545
private lateinit var binding: ActivityMyBinding
4646
private lateinit var googleMobileAdsConsentManager: GoogleMobileAdsConsentManager
4747

48+
// [START get_ad_size]
4849
// Get the ad size with screen width.
4950
private val adSize: AdSize
5051
get() {
@@ -61,6 +62,8 @@ class MyActivity : AppCompatActivity() {
6162
return AdSize.getCurrentOrientationAnchoredAdaptiveBannerAdSize(this, adWidth)
6263
}
6364

65+
// [END get_ad_size]
66+
6467
override fun onCreate(savedInstanceState: Bundle?) {
6568
super.onCreate(savedInstanceState)
6669
binding = ActivityMyBinding.inflate(layoutInflater)

kotlin/admob/BannerExample/app/src/main/java/com/google/android/gms/example/bannerexample/MainActivity.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class MainActivity : AppCompatActivity() {
4545
private lateinit var binding: ActivityMainBinding
4646
private lateinit var googleMobileAdsConsentManager: GoogleMobileAdsConsentManager
4747

48+
// [START get_ad_size]
4849
// Get the ad size with screen width.
4950
private val adSize: AdSize
5051
get() {
@@ -61,6 +62,8 @@ class MainActivity : AppCompatActivity() {
6162
return AdSize.getCurrentOrientationAnchoredAdaptiveBannerAdSize(this, adWidth)
6263
}
6364

65+
// [END get_ad_size]
66+
6467
override fun onCreate(savedInstanceState: Bundle?) {
6568
super.onCreate(savedInstanceState)
6669
binding = ActivityMainBinding.inflate(layoutInflater)

0 commit comments

Comments
 (0)