I tried using the testing Id, it displays the ad. Later on I put my own ID but it didn't display any ads.
Code:
setContentView(R.layout.activity_testing);
mInterstitialAd = new InterstitialAd(TestAd.this);
mInterstitialAd.setAdUnitId(getString(R.string.adunitid));
AdRequest adRequest=new AdRequest.Builder().build();
mInterstitialAd.loadAd(adRequest);
ad.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if(mInterstitialAd.isLoaded()){
mInterstitialAd.show();
}
else{
Toast.makeText(TestAd.this, "Ad Not Loaded", Toast.LENGTH_SHORT).show();
}
mInterstitialAd.setAdListener(new AdListener(){
#Override
public void onAdClosed() {
mInterstitialAd.loadAd(new AdRequest.Builder().build());
super.onAdClosed();
}
});
}
});
Java file for initialising:
public class Admob extends Application {
#Override
public void onCreate() {
super.onCreate();
MobileAds.initialize(this, new OnInitializationCompleteListener() {
#Override
public void onInitializationComplete(InitializationStatus initializationStatus) {
}
});
}}
Android Manifest :
android:name="com.test.Admob"
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="#string/appid"/>
First of all, You cannot show the live ads on debug mode,
If it is working with the test ids it should be cool with real ids when you release the app, as well.
But there is one more thing that you can use, I mean to be sure everything is working.
First of all, make every ids real contains the id at the manifest file.
After running your app, open your Logcat and simply write
test
like this,
get that id and update your AdRequest like this
AdRequest adRequest=new AdRequest.Builder().addTestDevice("id_here").build();
and re-run your app.
Congrats, you can see your ads with your real ids now! hope it helps!
UPDATE:
Old usage looks deprecated thanks #heisenberg3008
as the google suggests current usage should be like this
List<String> testDeviceIds = Arrays.asList("id_here");
RequestConfiguration configuration =
new RequestConfiguration.Builder().setTestDeviceIds(testDeviceIds).build();
MobileAds.setRequestConfiguration(configuration);
it is a one-time thing. So, no need to do that for every ad item, like before
Related
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.");
}
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?
I have set the device id of the phone I use for adMob testing as a const in my app. My testing device is not my day-to-day device.
Today I wanted to test a use case with a reward video and all of the sudden I get no fill or internal errors.
I took a look into the Log Cat and I saw that the device Id changed
By device Id I am referring to the one that comes in this log:
I/Ads: Use RequestConfiguration.Builder().setTestDeviceIds(Arrays.asList("THIS_ID_HERE") to get test ads on this device.
Why does it changed?
Is it because I uninstalled the prod version and installed a dev version of my app?
Does it happens randomly?
Can I prevent this behavior?
Device Id changes if you reset your phone. It may cause when you update your OS.
It does not change randomly.
Uninstalling prod version and installing a dev version should not change your device id(AFAIK).
As per google given try to use below credential for testing ads.In that case you will not need to add Device Id.
<!--Ad test credentials-->
<string name="admob_app_id">ca-app-pub-3940256099942544~3347511713</string>
<string name="banner_home_footer">ca-app-pub-3940256099942544/6300978111</string>
<string name="interstitial_full_screen">ca-app-pub-3940256099942544/1033173712</string>
<string name="rewarded_video">ca-app-pub-3940256099942544/5224354917</string>
<!--Ad live credentials-->
<string name="admob_app_id">add here your live app id</string>
<string name="banner_home_footer">add here your live footer id</string>
<string name="interstitial_full_screen">add here your live interstitial id</string>
<string name="rewarded_video">add here your live rewarded id</string>
Now use below function for shows testing ads.
//Banner Ads
private void loadBannerAds(AdView mAdView) {
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.build();
mAdView.loadAd(adRequest);
}
//Interstitial Ads
private void loadInterstitialAds(final InterstitialAd mInterstitialAd) {
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.build();
// Load ads into Interstitial Ads
mInterstitialAd.loadAd(adRequest);
mInterstitialAd.setAdListener(new AdListener() {
public void onAdLoaded() {
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
}
}
});
}
//RewardedVideo Ads
private void loadRewardedVideoAd(RewardedVideoAd mRewardedVideoAd) {
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.build();
mRewardedVideoAd.loadAd(context.getResources().getString(R.string.rewarded_video), adRequest);
mRewardedVideoAd.setRewardedVideoAdListener(new RewardedVideoAdListener() {
#Override
public void onRewarded(RewardItem rewardItem) {
}
#Override
public void onRewardedVideoAdLeftApplication() {
}
#Override
public void onRewardedVideoAdClosed() {
}
#Override
public void onRewardedVideoAdFailedToLoad(int errorCode) {
}
#Override
public void onRewardedVideoCompleted() {
}
#Override
public void onRewardedVideoAdLoaded() {
try {
if (mRewardedVideoAd.isLoaded()) {
mRewardedVideoAd.show();
}
} catch (Exception e) {
e.printStackTrace();
}
}
#Override
public void onRewardedVideoAdOpened() {
}
#Override
public void onRewardedVideoStarted() {
}
});
// showing the ad to user
// make sure the ad is loaded completely before showing it
if (mRewardedVideoAd.isLoaded()) {
mRewardedVideoAd.show();
}
}
I hope this can help you!
In my application, I have integrated ads from AdMob. When I use my test unit ID, ca-
app-pub-3940256099942544/1033173712, it shows test ads successfully. However, when I use my production ad unit ID, it shows nothing.
In logcat, I see ads loading error code 0. Why are my ads failing to load?
This is the code I am using:
MobileAds.initialize(activity, main_interstial_addunit_id);
final InterstitialAd interstitialAd = new InterstitialAd(activity);
interstitialAd.setAdUnitId(main_interstial_addunit_id);
AdRequest adRequest = new AdRequest.Builder().build();
interstitialAd.loadAd(adRequest);
interstitialAd.setAdListener(new AdListener() {
#Override
public void onAdLoaded() {
if (interstitialAd.isLoaded()) {
interstitialAd.show();
}
}
#Override
public void onAdClosed() {
}
#Override
public void onAdFailedToLoad(int i) {
super.onAdFailedToLoad(i);
}
#Override
public void onAdLeftApplication() {
super.onAdLeftApplication();
}
#Override
public void onAdOpened() {
super.onAdOpened();
}
});
return interstitialAd;
So, as you are getting error code 0 this means "failed to load ads"
From this conversation,
It could be that you have only recently created a new Ad Unit ID and requesting for live ads. It could take a few hours for ads to start getting served if that is that case. If you are receiving test ads then your implementation is fine. Just wait a few hours and see if you are able to receive live ads then. If not, can send us your Ad Unit ID for us to look into.
So, after some times you will be automatically get ads.
Important: Ad type of your ad unit id needs to be same of ad type where you set that id
public void adShow() {
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId("ca-app-pub-581420244534656/2222222");
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
} else {
requestNewInterstitial();
reseter();
}
mInterstitialAd.setAdListener(new AdListener() {
#Override
public void onAdClosed() {
requestNewInterstitial();
reseter();
}
});
}
private void requestNewInterstitial() {
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice("3D9834hiqewuiry48937498urequE")
.build();
mInterstitialAd.loadAd(adRequest);
}
}
I have tested the use of interstitial in my app using the default ad from google and it's working but now what must i do to make sure that the default orange ad is not displayed to users when I publish my app? I already have the AdUnitId.
So long as you have set a valid Ad unit id from the ad provider you're using, you should get real ads. The reason you most likely aren't seeing real ads is because of the line .addTestDevice("3D9834hiqewuiry48937498urequE") which basically says "Only show me the default orange ad on this device".
So, if you always test your app on the same device, this line is disabling real ads from appearing while you test (which is what you want). But this line will only disable real ads on a single device, the one you're using. On other devices, users will see real ads.