Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

After updating Google Ads SDK addTestDevice is deprecated, How to resolve?

After updating Google Ads SDK to 19.0.0 gives a deprecated warning message for addTestDevice(), while I searched this link for resolving the issue but not succeed. how can I resolve it?

Here my code

mAdView.loadAd(new RequestConfiguration.Builder
       .setTestDeviceIds(AdRequest.DEVICE_ID_EMULATOR) // show error
       .setTestDeviceIds(DEV_ID) // show error
       .build());

and developer site suggestion

Deprecated AdRequest.Builder.addTestDevice(). Use RequestConfiguration.Builder.setTestDeviceIds() instead.

like image 393
Attaullah Avatar asked Mar 05 '20 06:03

Attaullah


2 Answers

I did like this:

List<String> testDevices = new ArrayList<>();
testDevices.add(AdRequest.DEVICE_ID_EMULATOR);

RequestConfiguration requestConfiguration
    = new RequestConfiguration.Builder()
        .setTestDeviceIds(testDevices)
        .build();
MobileAds.setRequestConfiguration(requestConfiguration);

AdView adView = new AdView(context);
// ... invoke some methods of adView ...
adView.loadAd(new AdRequest.Builder().build());

The official reference says that a RequestConfiguration is the global configuration that will be used for every AdRequest. In my understanding, once you have setRequestConfiguration(), your AdRequests individually don't need to set test devices anymore.

like image 194
hata Avatar answered Oct 11 '22 12:10

hata


If you use Android Emulators there is no need to setTestDeviceIds() method because emulators are automatically configured as test devices .

But if you use a real devices or other emulators as a test device you must use it

List<String> testDeviceIds = Arrays.asList("33BE2250B43518CCDA7DE426D04EE231");
RequestConfiguration configuration =
    new RequestConfiguration.Builder().setTestDeviceIds(testDeviceIds).build();
MobileAds.setRequestConfiguration(configuration);   

To get the Device ID Check the logcat output for a message that looks like the one below, which shows you your device ID and how to add it as a test device:

I/Ads: Use RequestConfiguration.Builder.setTestDeviceIds(Arrays.asList("33BE2250B43518CCDA7DE426D04EE231"))
to get test ads on this device."

Source :

like image 38
Mohamed Ben Romdhane Avatar answered Oct 11 '22 13:10

Mohamed Ben Romdhane