Skip to content

Commit

Permalink
Add includecode snippets for Android adaptive banner getAdSize
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 692326001
  • Loading branch information
ericleich authored and copybara-github committed Nov 2, 2024
1 parent 6b5af49 commit a7699b0
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ private void initializeMobileAdsSdk() {
.start();
}

// [START get_ad_size]
// Get the ad size with screen width.
public AdSize getAdSize() {
DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
Expand All @@ -218,4 +219,5 @@ public AdSize getAdSize() {
int adWidth = (int) (adWidthPixels / density);
return AdSize.getCurrentOrientationAnchoredAdaptiveBannerAdSize(this, adWidth);
}
// [END get_ad_size]
}
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ private void initializeMobileAdsSdk() {

// [END request_ads]

// [START get_ad_size]
// Get the ad size with screen width.
public AdSize getAdSize() {
DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
Expand All @@ -227,4 +228,5 @@ public AdSize getAdSize() {
int adWidth = (int) (adWidthPixels / density);
return AdSize.getCurrentOrientationAnchoredAdaptiveBannerAdSize(this, adWidth);
}
// [END get_ad_size]
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class MyActivity : AppCompatActivity() {
private lateinit var binding: ActivityMyBinding
private lateinit var googleMobileAdsConsentManager: GoogleMobileAdsConsentManager

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

// [END get_ad_size]

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityMyBinding.inflate(layoutInflater)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class MainActivity : AppCompatActivity() {
private lateinit var binding: ActivityMainBinding
private lateinit var googleMobileAdsConsentManager: GoogleMobileAdsConsentManager

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

// [END get_ad_size]

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(layoutInflater)
Expand Down

0 comments on commit a7699b0

Please sign in to comment.