How to create facebook Banner Ads | Audience Network
Build.gradle:
....Copy any code....
implementation 'com.facebook.android:audience-network-sdk:5.4.1'
implementation 'com.facebook.android:audience-network-sdk:5.4.1'
AndroidManifest.xml:
....Copy the code as shown on the video....
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.facebook.ads.AudienceNetworkActivity"
android:configChanges="keyboardHidden|orientation|screenSize"/>
</application>
</manifest>
Step : Adding a Layout Container for the Banner Ad
In your layout file (for example: /res/layout/activity_main.xml), add a layout that will act as a container for your Ad.
Remember the id you set here as you will be referencing it in the code later.
activity_main.xml:
....Copy the code as shown on the video....
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
...
>
...
<LinearLayout
android:id="@+id/banner_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical"
/>
...
</RelativeLayout>
MainActivity java:
....Copy the code as shown on the video....
import com.facebook.ads.*; public class MainActivity extends AppCompatActivity { private AdView adView; ... // Instantiate an AdView object. // NOTE: the placement ID will eventually identify this as your App, you can ignore it for // now, while you are testing and replace it later when you have signed up. // While you are using this temporary code you will only get test ads and if you release // your code like this to the Google Play your users will not receive ads (you will get a no fill error). adView = new AdView(this, "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(); }
Ad Banner Sizes
Audience Network supports three ad sizes to be used in your
AdView
. The Banner unit's width is flexible with a minimum of 320px, and only the height is defined.Ad Format | AdSize Reference | Size | Recommendation |
---|---|---|---|
Standard Banner | BANNER_50 | 320x50 | This banner is best suited to phones |
Large Banner | BANNER_90 | 320x90 | This banner is best suited to tablets and larger devices |
Medium Rectangle | RECTANGLE_HEIGHT_250 | 320x250 | This format is best suited for scrollable feeds or end-of-level screens |
...Please do not copy the code...
The code is only made for our video, please do not copy it....
Banner 2495989693778711_2495992030445144
Text Facebook Ad In Mobile
How to create facebook Banner Ads | Audience Network
Reviewed by Code Labe
on
June 07, 2019
Rating: