Issue
I need to get the device width of the current orientation to display an AdMob adaptive banner. I tried to get it like this:
val deviceCurrentWidthDp = LocalConfiguration.current.screenWidthDp
val deviceCurrentDp = LocalConfiguration.current.densityDpi
val deviceCurrentWidth = deviceCurrentWidthDp / deviceCurrentDp
And passed it to display the banner which does not show the banner:
AndroidView(
factory = { context ->
AdView(context).apply {
adSize = AdSize.getCurrentOrientationAnchoredAdaptiveBannerAdSize(
context,
deviceCurrentWidth // works if replaced with 300
)
adUnitId = context.getString(R.string.ad_id_banner)
loadAd(AdRequest.Builder().build())
}
}
)
If I replace deviceCurrentWidth with a fixed value of 300, the banner shows alright. How can I fix this?
Thanks for your help!
Solution
Fixed it. Using deviceCurrentWidthDp.toInt() - 40 finally worked.
Answered By - Raw Hasan
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.