我想在我的应用中显示测试插页式广告。但它只适用于模拟器。真实设备日志显示
I/Ads: Trying mediation network:
I/Ads: Instantiating mediation adapter: com.google.DummyAdapter
I/Ads: No fill from any mediation ad networks.
W/Ads: Failed to load ad: 3
以下是一个调用广告的按钮示例。 我主要从https://developers.google.com/admob/android/interstitial
复制代码public class MainActivity extends AppCompatActivity {
private InterstitialAd mInterstitialAd;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId("ca-app-pub-3940256099942544/1033173712");
mInterstitialAd.loadAd(new AdRequest.Builder().addTestDevice(AdRequest.DEVICE_ID_EMULATOR).addTestDevice("C8769F4DD80CE4D614D7ED92F6F49E61").build());
mInterstitialAd.setAdListener(new AdListener() {
@Override
public void onAdClosed() {
// Load the next interstitial.
mInterstitialAd.loadAd(new AdRequest.Builder().addTestDevice(AdRequest.DEVICE_ID_EMULATOR).addTestDevice("C8769F4DD80CE4D614D7ED92F6F49E61").build());
}
});
}
public void onClickBtn(View v)
{
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
} else {
Log.d("TAG", "The interstitial wasn't loaded yet.");
}
}
App具有互联网访问权限。
请试一试。我想知道它是否适用于不同的设备。如果不是问题在哪里?
答案 0 :(得分:0)
我希望,这是您的问题,当您使用真实设备时,无需添加测试设备。
mInterstitialAd.loadAd(new AdRequest.Builder().addTestDevice(AdRequest.DEVICE_ID_EMULATOR).addTestDevice("C8769F4DD80CE4D614D7ED92F6F49E61").build());
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.loadAd(new AdRequest.Builder().build());
mInterstitialAd.setAdListener(new AdListener() {
@Override
public void onAdClosed() {
// Load the next interstitial.
mInterstitialAd.loadAd(new AdRequest.Builder().build());
}
});
}
myButton = ((Button) findViewById(R.id.myButtonn_button));
//myButton.setVisibility(View.INVISIBLE);
myButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
} else {
Log.d("TAG", "The interstitial wasn't loaded yet.");
}
}
});
Here就是示例