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!
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 am using interstitial ads from Admob in my app. Google rejects my app and claims ad fraud. They say that my app displays an ad after exiting the app.
I have changed my ad code to be sure that ad loading and ad displaying only happens when the activity is running and the app is in the foreground. Still they reject my app and claim ad fraud.
I am just doing basic interstitial code here:
implementation 'com.google.android.gms:play-services-ads:19.7.0'
public class AdManager {
boolean activityStarted;
public void onStart() {
activityStarted=true;
}
public void onStop() {
activityStarted=false;
}
public void initializeAds(Context context) {
MobileAds.initialize(context);
MobileAds.setAppMuted(true);
List<String> testDeviceIds = Arrays.asList("some id");
RequestConfiguration configuration =
new RequestConfiguration.Builder().setTestDeviceIds(testDeviceIds).build();
MobileAds.setRequestConfiguration(configuration);
}
public InterstitialAd getInterstialAdWithUnit(Context context) {
InterstitialAd mInterstitialAd = new InterstitialAd(context);
mInterstitialAd.setAdUnitId(BuildConfig.INTERSTITIAL_AD_UNIT_ID);
setAdListener(mInterstitialAd);
checkNewAdNeeded(mInterstitialAd);
return mInterstitialAd;
}
public void setAdListener(InterstitialAd mInterstitialAd) {
mInterstitialAd.setAdListener(new AdListener() {
#Override
public void onAdClosed() {
super.onAdClosed();
checkNewAdNeeded(mInterstitialAd);
}
});
}
public void showAdIfNeeded(InterstitialAd mInterstitialAd) {
if (activityStarted && mInterstitialAd.isLoaded())
mInterstitialAd.show();
else {
checkNewAdNeeded(mInterstitialAd);
}
}
public void requestNewInterstitial(InterstitialAd mInterstitialAd) {
AdRequest adRequest = new AdRequest.Builder()
.build();
mInterstitialAd.loadAd(adRequest);
}
public void checkNewAdNeeded(InterstitialAd mInterstitialAd) {
//do not load ad when acticity is stopped
if (activityStarted && !mInterstitialAd.isLoading() && !mInterstitialAd.isLoaded())
requestNewInterstitial(mInterstitialAd);
}
}
public class FullscreenActivity extends AppCompatActivity {
AdManager adManager=new AdManager();
public void onButtonClicked() {
//call another activity when Button is clicked and wait for return to display ad
activity.startActivityForResult(intent, requestCode);
runOnUiThread(new Runnable() {
#Override
public void run() {
adManager.checkNewAdNeeded(mInterstitialAd);
}
});
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
//back from other activity, try to display ads only if app has focus
if ( from activity xy) {
if (mHasFocus)
showAdWhileHasFocus();
else
showAdWhenHasFocus=true;
}
}
#Override
protected void onStart() {
super.onStart();
adManager.onStart();
}
#Override
protected void onStop() {
adManager.onStop();
super.onStop();
}
boolean showAdWhenHasFocus;
public void showAdWhileHasFocus() {
showAdWhenHasFocus=false;
adManager.showAdIfNeeded(mInterstitialAd,promotionAndAdsEvent);
}
boolean mHasFocus=false;
#Override
public void onWindowFocusChanged(boolean hasFocus) {
if (!hasFocus) {
} else {
if (showAdWhenHasFocus)
showAdWhileHasFocus();
}
super.onWindowFocusChanged(hasFocus);
}
#Override
protected void onDestroy() {
super.onDestroy();
}
}
I recently faced this issue. But got my app update approved after the following update:
We were having Interstitial ad right while opening the app, This was causing the next screen (Home dashboard) banner ad to hide behind the interstitial add. So I removed the interstitial. This got us the problem fixed.
It might be that playstore/Admob doesn't accept ad at app start, Might be they are trying to force us to use their app open ad instead of interstitial or any other ad unit.
In my case it turned out to be an old version in the test track. In the first version I had an interstitial when exiting the app - which is not allowed. I fixed the issue, but still my app got rejected. After about 10 more tries, I realized that the first version of the app (with the interstitial on exit) was still in the test track, so I removed (or updated) the test track version, and my app was approved.
Seems like after 5 months of app rejections with ad fraud claims my apps are passing review process again. The final change I made was to change the Interstitial class in my AdMob lib to the new API.
import com.google.android.gms.ads.interstitial.InterstitialAd;
InterstitialAd mInterstitialAd;
MobileAds.initialize(...
mInterstitialAd.setFullScreenContentCallback(...
mInterstitialAd.show(...
Admob has made a lot of restructuring and I was using the legacy API. Though it was not declared as legacy until a few weeks ago. The first claim was for version 19.4.0 (https://developers.google.com/admob/android/rel-notes) and it continued until version 19.7.0. Here is a discussion about the topic. https://groups.google.com/g/google-admob-ads-sdk/c/XTJ9kcgxvbY
My Ads donot show.
I am developing an app that requires Ads. Currently for testing, I have the app in the Internal Test Track of Google Play console for closed Testing. So, I cannot link it to an app in Play store in Admob.
So, to test them, all the while I have been Sample Test Ad Units, specifically Interstitial and Rewarded Video Ads. They load fine.
Today, I decided to switch to production Ads, as I wanted to release the App. So , I have created new Ad Units for both Rewarded and intersitial. Replaced the test Ad ID units with production Ad Unit IDs. I see "Ad failed to load : 0" .
Instead of using sample Ad Units, I tried making my device set Test Device. I see the follwing log
I/Ads: This request is sent from a test device.
I/Ads: Ad failed to load : 0
I am not sure what the issue is. I am still in the internal Test Track. Is the an issue? Do the production Ads work only when linked to an app in Google Play?
Please let me know where I am going wrong. Please see the attached image for Admob Ad units
The code is as show below:
Manifest.xml:
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-xxxxxxxxxxxxxxxx~xxxxxxxxxx" />
build.gradle:
implementation 'com.google.android.gms:play-services-ads:19.2.0'
Implementing AdMob :
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Rest of the code
MobileAds.initialize(this, new OnInitializationCompleteListener() {
#Override
public void onInitializationComplete(InitializationStatus initializationStatus) {
Log.w(TAG, " initialized mobile ad");
}
});
List<String> testDeviceIds = Arrays.asList("xxxxxxxxxxxxxxxxxxxxxxxxx");
RequestConfiguration configuration =
new RequestConfiguration.Builder().setTestDeviceIds(testDeviceIds).build();
MobileAds.setRequestConfiguration(configuration);
}
public void loadInterstitialAd(){
mInterstitialAd = new InterstitialAd(this);
this.rewardedAd = new RewardedAd(this, "ca-app-pub-xxxxxxxxxxxxxxxx/xxxxxxxxxx");
//mInterstitialAd.setAdUnitId("ca-app-pub-3940256099942544/1033173712");
mInterstitialAd.loadAd(new AdRequest.Builder().build());
mInterstitialAd.setAdListener(new AdListener() {
#Override
public void onAdLoaded() {
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
} else {
Log.d("TAG", "The interstitial wasn't loaded yet.");
}
}
#Override
public void onAdClosed() {
Log.w(TAG, "Interstitial ad cloed ");
onInterstitialshowed();
}
});
}
public void loadRewardedAd(){
this.rewardedAd = new RewardedAd(this, "ca-app-pub-xxxxxxxxxxxxxxxx/xxxxxxxxxx");
//this.rewardedAd = new RewardedAd(this, "ca-app-pub-3940256099942544/5224354917");
RewardedAdLoadCallback callback = new RewardedAdLoadCallback(){
#Override
public void onRewardedAdFailedToLoad(int i) {
super.onRewardedAdFailedToLoad(i);
}
#Override
public void onRewardedAdLoaded() {
super.onRewardedAdLoaded();
showRewardedAd();
}
};
this.rewardedAd.loadAd(new AdRequest.Builder().build(), callback);
}
public void showRewardedAd(){
if(rewardedAd.isLoaded()){
RewardedAdCallback callback = new RewardedAdCallback() {
#Override
public void onUserEarnedReward(#NonNull RewardItem rewardItem) {
Log.w(TAG, "onUserEarnedReward");
}
#Override
public void onRewardedAdOpened() {
super.onRewardedAdOpened();
Log.w(TAG, "OnRewardAdOpened");
}
#Override
public void onRewardedAdClosed() {
super.onRewardedAdClosed();
onRewardedAdLoadedOnClick();
}
#Override
public void onRewardedAdFailedToShow(int i) {
super.onRewardedAdFailedToShow(i);
Log.w(TAG, "onRewardedAdFailedToShow");
}
};
this.rewardedAd.show(this, callback);
}else{
Log.i(TAG, "Ad not loaded");
}
}
I had the same problem with SDK ANDROID LEVEL 30. When I changed it to SDK ANDROID LEVEL 29 the ADS showed.
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
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