I want to use the newly introduced Google AdMob Adaptive Banners in my app. The quickstart illustrates a function to dynamically calculate the AdSize by DisplayMetrics.
private AdSize getAdSize() {
// Step 2 - Determine the screen width (less decorations) to use for the ad width.
Display display = getWindowManager().getDefaultDisplay();
DisplayMetrics outMetrics = new DisplayMetrics();
display.getMetrics(outMetrics);
float widthPixels = outMetrics.widthPixels;
float density = outMetrics.density;
int adWidth = (int) (widthPixels / density);
// Step 3 - Get adaptive ad size and return for setting on the ad view.
return AdSize.getCurrentOrientationAnchoredAdaptiveBannerAdSize(this, adWidth);
}
But this function uses getWindowManager() of Activity for calculation. But I just pass Context to my Class. Anyway to get the DisplayMetrics with Context?