Java Admob ads正在加载但未显示
所以在我的LIBGDX游戏中,我试图弹劾Admob广告 即使在刷新60秒或按下home(主页)按钮并再次进入游戏后,它们仍然可以正常加载,但不会显示 我在这个网站上找到了一些答案,但没有一个有帮助 以下是Android Launcher类的代码:Java Admob ads正在加载但未显示,java,android,libgdx,admob,Java,Android,Libgdx,Admob,所以在我的LIBGDX游戏中,我试图弹劾Admob广告 即使在刷新60秒或按下home(主页)按钮并再次进入游戏后,它们仍然可以正常加载,但不会显示 我在这个网站上找到了一些答案,但没有一个有帮助 以下是Android Launcher类的代码: public class AndroidLauncher extends AndroidApplication implements AdHander{ private static final String TAG = "An
public class AndroidLauncher extends AndroidApplication implements AdHander{
private static final String TAG = "AndroidLauncher";
protected AdView adView;
private final int SHOW_ADS = 1;
private final int HIDE_ADS = 0;
Handler handler = new Handler(){
@Override
public void handleMessage(Message msg) {
switch (msg.what){
case SHOW_ADS:
adView.setVisibility(View.VISIBLE);
break;
case HIDE_ADS:
adView.setVisibility(View.GONE);
break;
}
}
};
@Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
RelativeLayout layout = new RelativeLayout(this);
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
View gameView = initializeForView(new Main(this), config);
adView = new AdView(this);
adView.setAdSize(AdSize.SMART_BANNER);
// HERE I IMPLEMENTED ADMOB TEST ID FOR BANNERS
adView.setAdUnitId("ca-app-pub-3940256099942544/6300978111");
adView.setBackgroundColor(Color.BLACK);
adView.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
int visibility = adView.getVisibility();
adView.setVisibility(AdView.GONE);
adView.setVisibility(visibility);
Log.i(TAG, "Ad loaded");
}
});
AdRequest.Builder builder = new AdRequest.Builder();
adView.loadAd(builder.build());
layout.addView(gameView);
RelativeLayout.LayoutParams adParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
adParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
adParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
layout.addView(adView, adParams);
setContentView(layout);
config.useImmersiveMode = true;
initialize(new Main(this), config);
}
@Override
public void showAds(boolean show) {
handler.sendEmptyMessage(show ? SHOW_ADS : HIDE_ADS);
}
}
我做错了什么?检查您的舱单,它应该与此类似:-
@Override
public void showAds(boolean show) {
Message msg = new Message();
msg.what = show ? SHOW_ADS : HIDE_ADS;
handler.sendMessage(msg);
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.serveroverload.recorder"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />
<!-- Include required permissions for Google Mobile Ads to run -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<!-- This meta-data tag is required to use Google Play Services. -->
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity
android:name="com.serveroverload.recorder.ui.HomeActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!--Include the AdActivity configChanges and theme. -->
<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>
</manifest>
这个问题解决了吗?