質問

I 've succesffuly integrated an admob banner in my android application and in the manifest file of my project i used the following configuration

  <activity android:name="com.google.android.gms.ads.AdActivity"
         android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/> 

But when i do change the screen orientation of my device the adview disappears?

What have i done wrong ?

役に立ちましたか?

解決

I solved it using the onConfigurationChanged method, Problem was when i do go back to portrait mode the ad-unit size was bigger than the available size.

Here is the solution

      @Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);

   LinearLayout parent= (LinearLayout) adView.getParent();
   parent.removeView(adView);

    /**
     * Admob paremetrization
     */

    final float density = getResources().getDisplayMetrics().density;
    int width = getWindowManager().getDefaultDisplay().getWidth();
    width  = Math.round(((float)width )/density);
    int height;
    if( width >= 936 ) // tablet
    {
      height = Math.round(density*60f);
    }
    else if( width >= 640 )
    {
      height = Math.round(density*50f);
    }
    else height = Math.round(density*32f);

            adView = new AdView(this);

            switch value of height adView.setAdSize(AdSize.FULL_BANNER or BANNER                  SMART_BANNER....);




    adView.setAdUnitId("ca-app-pub-xxxxxxxxxxxxxxxxxxxxxxxx");
    parent.addView(adView);
    AdRequest adRequest = new AdRequest.Builder().addTestDevice(AdRequest.DEVICE_ID_EMULATOR)        
            .addTestDevice("myDeviceId")   phone
            .build();
    adView.loadAd(adRequest);

}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top