我下载了一款安卓游戏,我想对它进行测试,但问题是,即使代码中包含'它也不会显示adMobs:
在main.java这里是adMob代码(我正在使用eclipse):
// AdMob
AdView adMob_smart;
InterstitialAd adMob_interstitial;
final boolean show_admob_smart = true; // show AdMob Smart banner
final boolean show_admob_interstitial = true; // show AdMob Interstitial
// AdMob Interstitial
if (num_games == 5) {
num_games = 0;
add_admob_interstitial();
}
// add_admob_smart
void add_admob_smart() {
if (show_admob_smart
&& ((ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo() != null) {
adMob_smart = new AdView(this);
adMob_smart.setAdUnitId(getString(R.string.adMob_smart));
adMob_smart.setAdSize(AdSize.SMART_BANNER);
((ViewGroup) findViewById(R.id.admob)).addView(adMob_smart);
com.google.android.gms.ads.AdRequest.Builder builder = new AdRequest.Builder();
// builder.addTestDevice(AdRequest.DEVICE_ID_EMULATOR).addTestDevice("4d0555dfcad9b000");
adMob_smart.loadAd(builder.build());
}
}
// add_admob_interstitial
void add_admob_interstitial() {
if (show_admob_interstitial
&& ((ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo() != null) {
adMob_interstitial = new InterstitialAd(this);
adMob_interstitial.setAdUnitId(getString(R.string.adMob_interstitial));
com.google.android.gms.ads.AdRequest.Builder builder = new AdRequest.Builder();
// builder.addTestDevice(AdRequest.DEVICE_ID_EMULATOR).addTestDevice("4d0555dfcad9b000");
adMob_interstitial.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
super.onAdLoaded();
if (findViewById(R.id.mess).getVisibility() == View.VISIBLE)
adMob_interstitial.show();
}
});
adMob_interstitial.loadAd(builder.build());
}
}
这是string.xml中的代码:
<!-- AdMob Smart Banner ID -->
<string name="adMob_smart">ca-app-pub-3310939034790481/3513231854</string>
<!-- AdMob Interstitial ID -->
<string name="adMob_interstitial">ca-app-pub-3310939034790481/3206249053</string>
我是android的新手,但到目前为止我正在学习如何开发Android游戏。
答案 0 :(得分:0)
如果您使用的是Android Studio,那么您是import com.google.android.gms.ads.MobileAds
吗?
或者您已经在build.gradle中添加了
maven {
url "https://maven.google.com"
}