Skip to content Skip to sidebar Skip to footer

Android Adsense. Can't See An Advertisement In An Application

I have a problem with AdSence. I have tried to resolve it the last couple of days but without any good results. I used developers guide but it still empty on the place of banner. W

Solution 1:

Change the new AdView declaration to:

adView =  new AdView(this, AdSize.BANNER, "a14def820df0417");

The engine object does not contain the context for its dimensions. The dimensions of the table row are in the Activity context "this"

Solution 2:

Well if you are setting your adView via xml/layout file then do as directed below:-

In your activity.xml file insert the following tag where you want your AdView to be shown:-

<com.google.ads.doubleclick.DfpAdView 
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        ads:adUnitId="/XXXXX/XXXXX"
        ads:adSize="BANNER"
        />

And in your Activity.java file write this code in your onCreate() Method of the Activity Life Cycle:-

// Look up the DfpAdView as a resource and load a request.
        adView = (DfpAdView)this.findViewById(R.id.adView);
        adView.loadAd(newAdRequest()); 

Now if you want to programmatic set the AdView in your Activity then follow the steps as directed below:-

Write the following code in your onCreate() method, I am demonstrating for Fragment, so write the following code in your onActivityCreated()Method.

// Create an ad view as a second header for now to meet deadlines
        DfpAdView mAdView=null; //you can also define this as a Global Variable.if (mAdView == null) {
            mAdView = newDfpAdView(getActivity(), AdSize.BANNER, "/XXXX/XXXX"); //give your adId incase of XXXX
            iaddHeight= (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 50, getResources().getDisplayMetrics()); //This code is used to set the height of the addHeight as 50 pixels, which could be used in layout params.RelativeLayoutfl=newRelativeLayout(this.getActivity());
            RelativeLayout.LayoutParamsflParams=newRelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, 
                    LayoutParams.WRAP_CONTENT);
            flParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);

            FrameLayout.LayoutParamspara=newFrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, 
                    LayoutParams.MATCH_PARENT); 
         para.setMargins(0, 0, 0,iaddHeight);

        getListView().setLayoutParams(para);

        this.getActivity().addContentView(fl, flParams);        
        fl.addView(mAdView,flParams);
        }
        mAdView.loadAd(newAdRequest());

Hope This can help Any Future users...

Post a Comment for "Android Adsense. Can't See An Advertisement In An Application"