Facebook banner ads in android studio

 Facebook banner ads in android studio -

Step 1 - in Manifest add internet permission

<uses-permission android:name="android.permission.INTERNET"/>

And Add dependencies in build.gradle file -

implementation 'androidx.annotation:annotation:1.2.0'
implementation 'com.facebook.android:audience-network-sdk:6.5.0'

Step 2 - Design your .xml file

<LinearLayout
android:id="@+id/banner_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />

Step 3 - Before onCreate method 

private AdView adView;

In onCreate method 

adView = new AdView(this, "IMG_16_9_APP_INSTALL#YOUR_PLACEMENT_ID", AdSize.BANNER_HEIGHT_50);

// Find the Ad Container
LinearLayout adContainer = (LinearLayout) findViewById(R.id.banner_container);

// Add the ad view to your activity layout
adContainer.addView(adView);

// Request an ad
adView.loadAd();

SDK link

Banner link

Post a Comment

Previous Post Next Post