Facebook Ads not showing android - android

I am developing and android application that needs to show Facebook Banner Ads, for that i have successfully generated Placement id and implemented the code suggested by Facebook developers website. But the problem is that ads are not showing. On debugging i find out this No Fill Error. I have searched this error on google but could not able to solve it. Any help will be appreciated. Here is my code :
AdView adView;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Instantiate an AdView view
adView = new AdView(this, PLACEMENT_ID, AdSize.BANNER_HEIGHT_50);
// Find the main layout of your activity
LinearLayout layout = (LinearLayout)findViewById(R.id.activityLayout);
// Add the ad view to your activity layout
layout.addView(adView);
adView.setAdListener(new AdListener() {
#Override
public void onError(Ad ad, AdError error) {
// Ad failed to load.
// Add code to hide the ad's view
}
#Override
public void onAdLoaded(Ad ad) {
// Ad was loaded
// Add code to show the ad's view
}
#Override
public void onAdClicked(Ad ad) {
// Use this function to detect when an ad was clicked.
}
});
// Request to load an ad
adView.loadAd();
}

After lots of searching i find out the solution why ads are not showing, actually my application is not live(in google play store) so try to login on your application with that Facebook account through which Placement id is generated. It will work.

Related

Why Admob test ads don't show

I've been having this problem for 3 days. I started developing applications with test ads to update the applications published in the store. But by no means did the test ads appear in the 2 apps. I suspected it because I was using old library. But when I created a new project and tested it, I saw test ads showing. I could not see any test ads in the applications published in the store. I would be very grateful for any help.
Error code:
failed to load: 3 --> ERROR_CODE_NO_FILL
build.gradle:
implementation 'com.google.android.gms:play-services-ads:19.4.0'
//and...
dependencies {
classpath 'com.android.tools.build:gradle:3.5.3'
classpath 'com.google.gms:google-services:4.3.0'
}
Activity:
private InterstitialAd mInterstitialAd;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity);
MobileAds.initialize(this, "ca-app-pub-3940256099942544~3347511713");
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId("ca-app-pub-3940256099942544/1033173712");
mInterstitialAd.loadAd(new AdRequest.Builder().build());
mInterstitialAd.setAdListener(new AdListener() {
#Override
public void onAdClosed() {
super.onAdClosed();
Log.d("testad","onAdClosed");
}
#Override
public void onAdFailedToLoad(int i) {
super.onAdFailedToLoad(i);
Log.d("testad","onAdFailedToLoad"+i);
mInterstitialAd.loadAd(new AdRequest.Builder().build());
}
#Override
public void onAdLeftApplication() {
super.onAdLeftApplication();
Log.d("testad","onAdLeftApplication");
}
#Override
public void onAdOpened() {
super.onAdOpened();
Log.d("testad","onAdOpened");
}
#Override
public void onAdLoaded() {
super.onAdLoaded();
Log.d("testad","onAdLoaded");
}
});
Android Manifest:
//...
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-3940256099942544~3347511713" />
</application>
I tried:
I reset the ad ID from device settings.
I added the device as a test device.
I tried with different network connection.
I tried with different device.
I'm facing the same issue in React Native. First, my test ads were showing then I uploaded the app to the google play store and the app store. A few days later ads limit was marked on my account after 15 days that limit is removed but now ads are not showing even not Test ads. I changed the bundle name and then test ads show. It means integration is ok there must be an issue on the account side.
If your test ads are working, but your real ads are not loading. It doesn't mean that your implementation is wrong. Admob doesn't show real until your app gets a certain amount of traffic. If there is low traffic on your app, then AdMob would show very few or no ads.
failed to load: 3 --> ERROR_CODE_NO_FILL
This error is clearly showing AdMob has no fill for your ads now. If test ads are working fine, then your real ads would load fine too, once AdMob starts to deliver them.
Don't try to load real ads from your devices, Admob will place a limited ad serving if they detect you are trying to load ads by yourself.
You are using an older AdMob SDK, the current version is 20.4.0. There are many API changes introduced in version 19.7.0 and some classes are deprecated and renamed.
The interstitial constructor you are using for initialization is now deprecated. You have to use the static load() method for creating an interstitial ad instance.
Now you have to initialize and use Interstitial ads like this
private InterstitialAd mInterstitialAd;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
.
.
.
AdRequest adRequest = new AdRequest.Builder().build();
InterstitialAd.load(this,"ca-app-pub-3940256099942544/1033173712", adRequest,
new InterstitialAdLoadCallback() {
#Override
public void onAdLoaded(#NonNull InterstitialAd interstitialAd) {
// The mInterstitialAd reference will be null until
// an ad is loaded.
mInterstitialAd = interstitialAd;
Log.i(TAG, "onAdLoaded");
}
#Override
public void onAdFailedToLoad(#NonNull LoadAdError loadAdError) {
// Handle the error
Log.i(TAG, loadAdError.getMessage());
mInterstitialAd = null;
}
});
}
Now show it by calling show() method
if (mInterstitialAd != null) {
mInterstitialAd.show(MyActivity.this);
} else {
Log.d("TAG", "The interstitial ad wasn't ready yet.");
}

Admob Ads not showing in android application

I created an account at Admob since a month, and i added payment method since 2 days ago.
a test device showing ads successfully. but other devices don't show any thing with error code:3
Ads: Ad failed to load : 3
public class MainActivity extends AppCompatActivity implements RewardedVideoAdListener {
private AdView adView;
private Button onePlayer, twoPlayer, exit;
private InterstitialAd mInterstitialAd;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MobileAds.initialize(this, getString(R.string.app_id));
MobileAds.initialize(this, initializationStatus -> {
});
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId(getString(R.string.instruction));
mInterstitialAd.loadAd(new AdRequest.Builder().addTestDevice("my-device-id").build());
mInterstitialAd.setAdListener(InterstitialListener);
adView = findViewById(R.id.adView);
adView.loadAd(new AdRequest.Builder().addTestDevice("my-device-id").build());
adView.setAdListener(adListener);
}
}
and i created a listener for InterstitialAd
private AdListener InterstitialListener = new AdListener() {
#Override
public void onAdLoaded() {
// Code to be executed when an ad finishes loading.
mInterstitialAd.show();
}
#Override
public void onAdFailedToLoad(int errorCode) {
// Code to be executed when an ad request fails.
Toast.makeText(getApplicationContext(), "errorCode " + errorCode + "", Toast.LENGTH_LONG).show();
}
#Override
public void onAdOpened() {
// Code to be executed when the ad is displayed.
}
#Override
public void onAdClicked() {
// Code to be executed when the user clicks on an ad.
}
#Override
public void onAdLeftApplication() {
// Code to be executed when the user has left the app.
}
#Override
public void onAdClosed() {
// Code to be executed when the interstitial ad is closed.
}
};
and this is banner xml:
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="#+id/adView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="#string/banner">
</com.google.android.gms.ads.AdView>
Note: the app doesn't uploaded to store yet!
how can i fix this problem?
This answer might help someone in future. I had the same problem. Ads were working fine in test devices. But in real device it did not display any ad.
I published my app to google play and downloaded it. In the app downloaded from google play, Ads are showing fine. I did not make any changes to the code
I am not sure why this happens, it's kind of black box.
Some answers in stack overflow says no need to publish app for showing ads. But it was not true in my case.
Your code seems fine.
Are you using this test unit ID for your banner?
ca-app-pub-3940256099942544/6300978111
Or are you using the one from your AdMob account?

Issue getting ads to show

I'm trying to get my Google ads to show on an Android app. I've done these things already:
Connect to Firebase
Added gradle file code
Set up admob account
Have the proper code
It seems like there's nothing more for me to do, but they're not showing up.
Here's an example of what I have in onCreate.
//AdMob initialization
MobileAds.initialize(this, "**myADmob ID**");
mAdView = findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
AdView adView = new AdView(this);
adView.setAdSize(AdSize.SMART_BANNER);
mAdView.setAdListener(new AdListener() {
#Override
public void onAdLoaded() {
// Code to be executed when an ad finishes loading.
}
#Override
public void onAdFailedToLoad(int errorCode) {
// Code to be executed when an ad request fails.
}
#Override
public void onAdOpened() {
// Code to be executed when an ad opens an overlay that
// covers the screen.
}
#Override
public void onAdLeftApplication() {
// Code to be executed when the user has left the app.
}
#Override
public void onAdClosed() {
// Code to be executed when when the user is about to return
// to the app after tapping on an ad.
}
});
Here's a sample from my xml.
<com.google.android.gms.ads.AdView
android:id="#+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
app:adSize="SMART_BANNER"
app:adUnitId="banner_ad_unit_id_main"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="457dp">
</com.google.android.gms.ads.AdView>
Try this. As per Google Documentation,
Note: If an app tries to load a banner that's too big for its layout,
the SDK won't display it. Instead, an error message will be written to
the log.
Make sure you are giving enough space for the ad to show up(which is 320x50 dp). You can try hard-code the value for testing.
Can you also check the log and check the internet permissions in AndroidManifest.xml

Where to place AdMob interstitial ad in ViewPager

I have published an app in google play having the ad in it, few days ago I got the following email from google Admob.
We are alerting you that your app is currently in violation of the AdMob program policies. Importantly, this will require action on your part to ensure no disruption in ad serving. Please read below for more information on the actions you need to take:
LAYOUT ENCOURAGES ACCIDENTAL CLICKS - INTERSTITIAL ADS:
Publishers are not permitted to encourage users to click AdMob interstitial ads in any way. This includes any implementation that may encourage accidental clicks, such as placing an interstitial ad in a way that prevents viewing the app’s core content or placing an interstitial ad in a way that interferes with navigating or interacting with the app’s core content and functionality.
Please review how you’ve implemented interstitial ads and be mindful of the following common examples of non-compliant implementations:
Interstitial ads that appear before the app has opened or after the app has closed.
Interstitial ads that are triggered after a user closes another interstitial ad.
Interstitial ads loading unexpectedly while a user is viewing the app’s content. Remember to only serve interstitials between pages of content.
Interstitial ads that trigger after every user click.
Interstitial ads that appear during periods of game play or heavy user interaction.
Now below is my MainActivity. I need help to place the ad in appropriate area
public class MainActivity extends Activity {
private InterstitialAd interstitial;
// static int p;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ExtendedViewPager mViewPager = (ExtendedViewPager) findViewById(R.id.view_pager);
mViewPager.setAdapter(new TouchImageAdapter());
mViewPager.setCurrentItem(5);
// Prepare the Interstitial Ad
interstitial = new InterstitialAd(MainActivity.this);
// Insert the Ad Unit ID
interstitial.setAdUnitId("xxxxxxxxxxxxxxxxxxxxxxxx");
//Locate the Banner Ad in activity_main.xml
AdView adView = (AdView) this.findViewById(R.id.adView);
// Request for Ads
AdRequest adRequest = new AdRequest.Builder()
// Add a test device to show Test Ads
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("")
.build();
// Load ads into Banner Ads
adView.loadAd(adRequest);
// Load ads into Interstitial Ads
interstitial.loadAd(adRequest);
// Prepare an Interstitial Ad Listener
interstitial.setAdListener(new AdListener() {
public void onAdLoaded() {
// Call displayInterstitial() function
displayInterstitial();
}
});
}
public void displayInterstitial() {
// If Ads are loaded, show Interstitial else show nothing.
if (interstitial.isLoaded()) {
interstitial.show();
}
}
class TouchImageAdapter extends PagerAdapter {
private int[] images = { R.drawable.file_page05,R.drawable.file_page04,R.drawable.file_page03,R.drawable.file_page02,R.drawable.file_page01};
#Override
public int getCount() {
return images.length;
}
#Override
public View instantiateItem(ViewGroup container, int position) {
TouchImageView img = new TouchImageView(container.getContext());
img.setImageResource(images[position]);
container.addView(img, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
return img;
}
#Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((View) object);
}
#Override
public boolean isViewFromObject(View view, Object object) {
return view == object;
}
}
}
Creating ad will take some time. You are displaying the ad after the viewpager is displayed. This will lead to a case where the user is navigating through viewpager and suddenly ad is loaded. This is against the ad policy.
Before loading the viewpager, you have check whether ad is loaded. If ad is loaded, then display ad and on closing the ad, display viewpager. Else directly display viewpager.
I will usually load the ad in the launcher activity and display when needed.

Not able to see any Ad in by AdView Banner using AdMob

Here is my Activity class
public class MainActivity extends Activity {
private InterstitialAd interstitial;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Prepare the Interstitial Ad
interstitial = new InterstitialAd(MainActivity.this);
// Insert the Ad Unit ID
interstitial.setAdUnitId("Ad-ID");
//Locate the Banner Ad in activity_main.xml
AdView adView = (AdView)findViewById(R.id.adView);
// Request for Ads
AdRequest.Builder adRequestBuilder=new AdRequest.Builder();
// Add a test device to show Test Ads
adRequestBuilder .addTestDevice(AdRequest.DEVICE_ID_EMULATOR);
adRequestBuilder.addTestDevice("abcd").build();
// Load ads into Banner Ads
//adView.setAdUnitId("Ad-ID");
adView.loadAd(adRequestBuilder.build());
interstitial.setAdListener(new AdListener() {
public void onAdLoaded() {
// Call displayInterstitial() function
displayInterstitial();
}
});
}//end of onCreate
protected void displayInterstitial() {
// TODO Auto-generated method stub
if (interstitial.isLoaded()) {
interstitial.show();
}
}
This is my simple XML Layout
<com.google.android.gms.ads.AdView
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="Ad-ID" />
I tried running the application there is no error shown and I am not able to seen any sample ad's in my layout when I run it.
Please let me know where was I mistaken.
You need to replace your own Ad Unit Id in your code and xml file.
adRequestBuilder.addTestDevice("abcd").build(); Here abcd is not a vaild device id. If you are running your app on a real device then in Logcat you will find its device id.
You will have to put that id here in spite of abcd.
In Logcat you will get a line saying,
To get test ads on this device, call adRequest.addTestDevice("SOME_ID_HERE");
You will have to put this id shown here in your code.

Categories

Resources