distante
distante

Reputation: 7025

My device id for AdMob Testing changed (Android)

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.

Upvotes: 1

Views: 2856

Answers (2)

Hardik Talaviya
Hardik Talaviya

Reputation: 1496

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!

Upvotes: 0

Rasel
Rasel

Reputation: 5734

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).

Upvotes: 2

Related Questions