Admob在模拟器,logcat表单模拟器上显示测试横幅:
05-03 08:07:44.032 798-798/ru.xxx.xxx I/Ads: Starting ad request.
05-03 08:07:45.572 798-798/ru.xxx.xxx W/Ads: Loading already in progress, saving this object for future refreshes.
05-03 08:07:58.812 798-798/ru.xxx.xxx I/Ads: Scheduling ad refresh 60000 milliseconds from now.
05-03 08:07:58.922 798-798/ru.xxx.xxx I/Ads: Ad finished loading.
但是当我在设备上运行app时,admob不显示测试和真实横幅。来自真实设备的logcat:
05-03 13:17:23.388 28142-28142/ru.xxx.xxx I/Ads: Starting ad request.
05-03 13:17:23.983 28142-28142/ru.xxx.xxx W/Ads: Loading already in progress, saving this object for future refreshes.
05-03 13:17:34.748 28142-28247/ru.xxx.xxx W/Ads: There was a problem getting an ad response. ErrorCode: 0
05-03 13:17:34.749 28142-28142/ru.xxx.xxx W/Ads: Failed to load ad: 0
主要活动:
public class AndroidLauncher extends AndroidApplication implements AdsController {
private static final String BANNER_AD_UNIT_ID = "xxx";
AdView bannerAd;
InterstitialAd interstitialAd;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
// Create a gameView and a bannerAd AdView
View gameView = initializeForView(new RunawayCat(this), config);
setupAds();
// Define the layout
RelativeLayout layout = new RelativeLayout(this);
layout.addView(gameView, ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.ALIGN_PARENT_TOP);
params.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
layout.addView(bannerAd, params);
setContentView(layout);
}
public void setupAds() {
bannerAd = new AdView(this);
bannerAd.setVisibility(View.INVISIBLE);
bannerAd.setAdUnitId(BANNER_AD_UNIT_ID);
bannerAd.setAdSize(AdSize.SMART_BANNER);
AdRequest.Builder builder = new AdRequest.Builder();
AdRequest ad = builder.build();
builder.addTestDevice("xxxx");
bannerAd.loadAd(ad);
}
@Override
public void showBannerAd() {
runOnUiThread(new Runnable() {
@Override
public void run() {
bannerAd.setVisibility(View.VISIBLE);
AdRequest.Builder builder = new AdRequest.Builder();
AdRequest ad = builder.build();
bannerAd.loadAd(ad);
}
});
}
}
清单
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ru.romavaleev.runawaycat"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="23" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/GdxTheme" >
<activity
android:name=".AndroidLauncher"
android:label="@string/app_name"
android:screenOrientation="landscape"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version"/>
<activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="@android:style/Theme.Translucent" />
</application>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
</manifest>
admob帐户未被禁止,我在3台设备上进行了测试。清单中的权限是正确的
答案 0 :(得分:0)
尝试删除builder.addTestDevice("xxxx")
像这样的事情
AdRequest.Builder builder = new AdRequest.Builder();
AdRequest ad = builder.build();
bannerAd.loadAd(ad);
我每天都会整合广告,我从来没有需要添加测试设备,如果您使用广告的测试ID,它总是显示测试广告
您可以使用此测试横幅ID
ca-app-pub-3940256099942544/6300978111
并在生成最终APK
答案 1 :(得分:0)
只是一个猜测。 构建广告后,您可能正在分配testDevice 吗?
AdRequest ad = builder.build();
builder.addTestDevice("xxxx");
开始这两行:
builder.addTestDevice("xxxx");
AdRequest ad = builder.build();