Reputation:
I've added a Facebook banner ad in my Android app . I used a valid banner ID but there is nothing . I want to know if my code has something wrong .
Here is my code
in build.app
compile 'com.facebook.android:audience-network-sdk:4.18.0'
in MainActivity
com.facebook.ads.AdView adView2 = new com.facebook.ads.AdView(this, "my_banner_id",AdSize.BANNER_HEIGHT_50);
LinearLayout adContainer = (LinearLayout) findViewById(R.id.banner_container);
adContainer.addView(adView2);
adView2.loadAd();
in activity_main.xml
<LinearLayout
android:id="@+id/banner_container"
android:layout_width="match_parent"
android:layout_height="55dp"
android:orientation="vertical"
/>
Upvotes: 2
Views: 6377
Reputation: 1918
Take a step by step approach with the facebook ads sdk. Make sure you use the latest version, as old version will not receive ads. I was running an older version and ads stopped rendering.
In order to receive ads, you must have a facebook account on the test device, that is linked to the monetisation manager property you are trying to monetise.
Here is how I render a FAN banner. keep in mind, I have a rendering method which receives adConfig
as a configuration object which contains the facebook adUnit and a parent
object, which is the layout container where I want to render the add (these are specific to my project only):
if (adConfig != null && adConfig.getAdUnit() != null) {
Log.d(TAG, "displayBanner " + adConfig.getClass().getSimpleName() + " : " + adConfig.getAdUnit());
parent.setVisibility(View.VISIBLE);
parent.removeAllViews();
com.facebook.ads.AdView adView = new com.facebook.ads.AdView(parent.getContext(), adConfig.getAdUnit(), com.facebook.ads.AdSize.BANNER_HEIGHT_50);
parent.addView(adView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
adView.loadAd();
}
Upvotes: 1
Reputation:
It works when I change:
app.build
from
compile 'com.facebook.android:audience-network-sdk:4.18.0'
to
compile 'com.facebook.android:audience-network-sdk:4.23.0'
In MainActivity
from
com.facebook.ads.AdView adView2 = new com.facebook.ads.AdView(this, "my_banner_id",AdSize.BANNER_HEIGHT_50);
to
Resources res = getResources();
com.facebook.ads.AdView adView2 = new com.facebook.ads.AdView(this,res.getString(R.string.facebook_banner),AdSize.BANNER_HEIGHT_50);
But I still have this error in Logs
TeamDetails has leaked IntentReceiver com.facebook.ads.internal.DisplayAdController$c@3012f931 that was originally registered here. Are you missing a call to unregisterReceiver()?
I don't know why this error still appears in Logs
.
Upvotes: 1
Reputation: 4121
Steps to resolve this issue:
Add this testing id to your onCreate method.
AdSettings.addTestDevice("you hash id");
Sometime due to incomplete payroll we have to face problem. Cross check your payroll information is complete.
For more details on this issue check this link. reference
Upvotes: 0