我有问题。我的Admob已经设置了一段时间,没有任何问题,但我注意到了问题。广告已成功加载(我看到DDMS的消息),但不会显示。在定期60秒刷新或我打开登录到Google Plus之后,它将显示出来。这个问题仅在Google Play Services Admob中发生,而不会与Admobsdk Jar一起发生。我会切换到Admob Jar,但是我正在为排行榜和成就使用Google Play游戏服务。
我怀疑问题是未显示的视图或Inproper设置。
再次,AD将在等待60秒(以及AD刷新)后表现出来,或者当我启动Google Play Services的登录屏幕时。
我正在添加我的代码,也应该提到我已经切换到新的ADMOB网站,我重复说,如果我使用admob jar文件,则不会发生这个问题(然后在2-3秒内显示该广告普通的)。我已经删除了Google Play游戏服务代码(它们不会影响此问题,因为我在没有其他应用程序中尝试了其他应用程序,而且问题仍然存在)。
主动脉代码:
public class MainActivity extends AndroidApplication {
public static enum AdsStatus {
SHOW_ADS, HIDE_ADS;
}
protected RelativeLayout layout;
protected static AdView adMobView;
public static class InnerHandler extends Handler {
WeakReference<MainActivity> mActivity;
InnerHandler(MainActivityactivity) {
mActivity = new WeakReference<MainActivity>(activity);
}
@Override
public void handleMessage(final Message msg) {
if(msg.obj instanceof AdsStatus) {
switch((AdsStatus)msg.obj) {
case SHOW_ADS:
mActivity.get().showAds();
break;
case HIDE_ADS:
mActivity.get().hideAds();
break;
}
}
}
}
protected Handler handler = new InnerHandler(this);
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Create the layout
layout = new RelativeLayout(this);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
// Create the libgdx View
View gameView = initializeForView(new MainApplicationListener(), true);
layout.addView(gameView);
//Ad Mob
final DisplayMetrics displayMetrics = MainActivity.this
.getApplicationContext().getResources()
.getDisplayMetrics();
if (displayMetrics.widthPixels >= 800 && displayMetrics.heightPixels >= 480) {
if(adMobView != null) {
adMobView.destroy();
}
adMobView = new AdView(AirDance.this);
adMobView.setAdUnitId(<MY_ID_IS_HERE>);
adMobView.setAdSize(AdSize.SMART_BANNER);
RelativeLayout.LayoutParams adParams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
adParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
adParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(<MY_DEVICE_IS_HERE>)
.build();
adMobView.loadAd(adRequest);
layout.addView(adMobView, adParams);
}
// Hook it all up
setContentView(layout);
}
@Override
protected void onResume() {
super.onResume();
AppRater.applicationLaunched(this, analytics);
if(adMobView != null) {
adMobView.resume();
}
}
@Override
protected void onPause() {
super.onPause();
if(adMobView != null) {
adMobView.pause();
}
}
@Override
protected void onDestroy() {
super.onDestroy();
if(adMobView != null) {
adMobView.destroy();
adMobView = null;
}
}
public void showAds() {
runOnUiThread(new Runnable() {
@Override
public void run() {
if(adMobView != null) {
adMobView.setEnabled(true);
adMobView.setVisibility(View.VISIBLE);
}
}
});
}
public void hideAds() {
runOnUiThread(new Runnable() {
@Override
public void run() {
if(adMobView != null) {
adMobView.setEnabled(false);
adMobView.setVisibility(View.GONE);
}
}
});
}
}
这是AndroidManifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="..."
android:installLocation="auto"
android:versionCode="16"
android:versionName="1.2.6" >
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-feature android:name="android.hardware.screen.landscape"/>
<uses-feature android:name="android.hardware.touchscreen.multitouch" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="MainActivity">
<meta-data android:name="com.google.android.gms.games.APP_ID"
android:value="@string/app_id" />
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity
android:name="...MainActivity"
android:label="MainActivity"
android:screenOrientation="landscape">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- adMob -->
<activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
</application>
</manifest>
编辑:好的,因此,在我锁定并在应用程序打开的情况下锁定屏幕后,广告可见,您也可以单击"隐形广告"
编辑:好吧,我认为我解决了。我只是手动重新加载了整个布局onadload事件。无论如何,这只是功能解决方案,它不能解释为什么它发生在Google Play中服务管理员
adMobView.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
super.onAdLoaded();
MainActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
layout.requestLayout();
}
});
}
});
没人回答说明,我将考虑解决这个问题。我只是手动重新加载了整个布局onadload事件。无论如何,这只是功能解决方案,它不能解释为什么它发生在Google Play Services Admob中。
adMobView.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
super.onAdLoaded();
MainActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
layout.requestLayout();
}
});
}
});
另外,如用户3263204所述,您可以尝试此
adMobView.setBackgroundColor(Color.BLACK);
解决您的问题。
上述解决方案有效。即使显示横幅的一种更简单的方法是设置其背景。
adMobView.setBackgroundColor(Color.BLACK);
正如User3263204所说,您可以使用setbackgroundColor来使您出现。您可以使背景透明,如果(就我而言),您对其他事物的建议:
adMobView.setBackgroundColor(getResources().getColor(android.R.color.transparent));
您还可以请求WindowFeature(window.feature_no_title);并设置为全屏和广告显示。
banner.setBackgroundColor(Color.TRANSPARENT);
这似乎为我解决了问题。另请确保从UI线程中运行横幅创建代码。
activity.runOnUiThread(new Runnable()
{
@Override
public void run()
{
// all your banner creation code is here
banner.setBackgroundColor(Color.TRANSPARENT);
}
});