Facebook Audience Network

random

Facebook Banner ads in android studio

Update Website Link



Facebook banner ads in android studio


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 FormatAdSize ReferenceSizeRecommendation
Standard BannerBANNER_50320x50This banner is best suited to phones
Large BannerBANNER_90320x90This banner is best suited to tablets and larger devices
Medium RectangleRECTANGLE_HEIGHT_250320x250This 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
Facebook Banner ads in android studio Reviewed by Code Labe on October 08, 2019 Rating: 5

Contact Form

Name

Email *

Message *

Powered by Blogger.