❂ How to implement Facebook ads in android, i will guide you how to impenitent Facebook Interstitial Ads.
✺ To easily apply ads ✺
❂ please watch our YouTube video first..❂
❂ Gradle Scripts ✺
implementation 'com.facebook.android:audience-network-sdk:4.99.1'
❂ AndroidManifest.xml ✺
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.facebook_facebook_interstitial_ads">
<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>
❂ MainActivity.java ✺
package com.example.facebook_facebook_interstitial_ads;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import com.facebook.ads.AbstractAdListener;
import com.facebook.ads.Ad;
public class MainActivity extends AppCompatActivity {
com.facebook.ads.InterstitialAd interstitial;
Ad adfacebook;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
interstitial = new com.facebook.ads.InterstitialAd(MainActivity.this, getString(R.string.facebook_interstial));
interstitial.setAdListener(new AbstractAdListener() {
public void onAdLoaded(Ad ad) {
adfacebook = ad;
}
});
interstitial.loadAd();
}
@Override
public void onBackPressed() {
if (adfacebook == interstitial) {
interstitial.show();
}
super.onBackPressed();
}
}
❂Please do not use this Advertising code❂
❂ Strings.xml ✺
<resources>
<string name="app_name">Facebook_facebook_Interstitial_ads</string>
<string name="facebook_interstial">394161391135441_394162127802034</string>
</resources>
0 Comments