Facebook banner ads into your app android studio
Step 1: add Facebook dependencies build.gradle in your project
dependencies {
// fakebook sdk
implementation 'androidx.annotation:annotation:1.0.0'
implementation 'com.facebook.android:audience-network-sdk:6.2.0'
}
step 2: add this linear layout where you want to show banner
<LinearLayout
android:id="@+id/banner_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent" />
step 3: create variables into main activity
AdView adViewbanner;
LinearLayout adContainerlayout;
step 4: paste this method in main activity
private void Loadbannerads() {
adContainerlayout = (LinearLayout) findViewById(R.id.banner_container);
AudienceNetworkAds.initialize(this);
// AdSettings.addTestDevice(getResources().getString(R.string.testid));
// ad this if want you see preview of your banner
//to find your test id go to logcat section and search addTestDevice
// you will find this link AdSettings.addTestDevice("5ade1b55-0c7d-4e1a-bd60-92ff620e6688");
// paste this into your string file 5ade1b55-0c7d-4e1a-bd60-92ff620e6688 after that you can see a perview of your ads
adViewbanner = new AdView(this, getResources().getString(R.string.Adid_banner), AdSize.BANNER_HEIGHT_90);
adContainerlayout.addView(adViewbanner);
adViewbanner.loadAd();
}
step 5: call this method Loadbannerads() when you want to show banner . if you want to show when app stated then call this inside create method
// paste inside on create method
Loadbannerads();
Comments
Post a Comment