我整合了google admob广告,但它显示的错误为
W / Ads:收到广告回复时出现问题。 ErrorCode:0 08-09 16:05:43.933 24002-24002 / com.locationtracking W / Ads:无法加载广告:0
我创建了一个新的广告ID,并复制了interstital广告单元ID和应用ID,但它无效。
但是,当我使用testing interstial ID时,它会显示广告。但是当我复制并使用创建的interstital id时,它不会显示广告。过去几天,我在这方面苦苦挣扎。我创建了新帐户并进行了检查。还是一样的错误。
MobileAds.initialize(this, "ca-app-pub-9172823052987868~3234462570");
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId("ca-app-pub-9172823052987868/8576265071");
AdRequest adRequestInterstitial = new AdRequest.Builder().addTestDevice("deviceid").build();
mInterstitialAd.loadAd(adRequestInterstitial);
mInterstitialAd.setAdListener(new AdListener() {
@Override
public void onAdClosed() {
}
@Override
public void onAdLoaded() {
mAdIsLoading = false;
showInterstitial();
}
@Override
public void onAdFailedToLoad(int errorCode) {
mAdIsLoading = false;
}
});
}
private void showInterstitial() {
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
AdRequest adRequest = new AdRequest.Builder().addTestDevice("deviceid").build();
mInterstitialAd.loadAd(adRequest);
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.android.gms:play-services-ads:9.2.1'
compile 'com.google.android.gms:play-services-analytics:9.2.1'
}
答案 0 :(得分:0)
您无法在测试设备中显示真实广告,因此您在上传apk =>时应删除测试设备代码。改变你的代码
$scope.$on('google-maps-ready', function(){
$scope.initLocation();
});
答案 1 :(得分:0)
常见错误!您的代码没有错误。一切都很好。
你只需要稍等一下。您的广告ID是新创建的,因此从Google服务器获取广告需要一些时间。您可以通过添加为早期应用创建的横幅/插页式广告ID来验证这一点,并且您会发现它们有效。所以给它一些时间,它会尽快工作。至少对我来说,它总是发生。
W / Ads:收到广告回复时出现问题。 ErrorCode:0 08-09 16:05:43.933 24002-24002 / com.locationtracking W / Ads:无法加载广告:0
删除addTestDevice(" deviceid");从您的代码中显示真实广告
AdRequest adRequestInterstitial = new AdRequest.Builder().addTestDevice("deviceid").build();
到
AdRequest adRequestInterstitial = new AdRequest.Builder().build();
尝试以下代码运行良好:
public class MainActivity extends AppCompatActivity {
InterstitialAd mInterstitialAd;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
////////////////////////// banner/////////////////////////
AdView mAdView = (AdView) findViewById(R.id.adView);
//AdRequest adRequest = new AdRequest.Builder().addTestDevice("7339C0A9091FA2D6AA9A2BF29077B5EA").build();
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
///////////////////////////////////////////////////////////
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId(getResources().getString(R.string.interstitial_unit_id));
mInterstitialAd.setAdListener(new AdListener() {
@Override
public void onAdClosed() {
loadAdd();
}
});
loadAdd();
}
@Override
protected void onStart() {
super.onStart();
showInterstitial();
}
@Override
protected void onStop() {
super.onStop();
showInterstitial();
}
//////////////////////////////////add Interstitial section//////////////////////////////////////////////
private void showInterstitial() {
// Show the ad if it's ready. Otherwise toast and restart the game.
if (mInterstitialAd != null && mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
} else {
//Toast.makeText(this, "Ad did not load", Toast.LENGTH_SHORT).show();
loadAdd();
}
}
private void loadAdd() {
// Request a new ad if one isn't already loaded, hide the button, and kick off the timer.
if (!mInterstitialAd.isLoading() && !mInterstitialAd.isLoaded()) {
//AdRequest adRequest = new AdRequest.Builder().addTestDevice("7339C0A9091FA2D6AA9A2BF29077B5EA").build();
AdRequest adRequest = new AdRequest.Builder().build();
mInterstitialAd.loadAd(adRequest);
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
}
compile 'com.google.android.gms:play-services-ads:8.3.0'