嗨,我正在将Chartboost集成到我的游戏中,但广告没有在实时和测试模式下展示。我完全按照本教程进行操作,我的代码https://github.com/itsabhiaryan/AdService-LibGDX
中没有错误在https://github.com/itsabhiaryan/AdService-LibGDX/blob/master/android/src/com/its/adservice/AndroidLauncher.java第34行中,我更改为ad = new ChartBoostHelper(this);我删除了onSaveInstanceState和onRestoreInstanceState方法,还进行了其他更改。我在正确的地方调用了show ads方法,但它没有显示。
我注册了Chartboost,并相应地添加了我的appId和签名,还将该设置设置为横向广告和非页内广告。我已按照本教程中的说明修改了AndroidManifest文件,并将jar文件添加到了/ android / libs文件夹中。我错过了什么还是做错了什么?
这是我的android / AndroidLauncher.java和ChartBoostHelper,而Ad类与github链接中的相同。
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.RelativeLayout;
import com.badlogic.gdx.backends.android.AndroidApplication;
import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;
public class AndroidLauncher extends AndroidApplication implements ActionResolver {
private Ad ad;
public RelativeLayout layout;
View gameView;
@Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
config.useAccelerometer = false;
config.useCompass = false;
config.useImmersiveMode = true;
layout = new RelativeLayout(this);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
layout.setLayoutParams(params);
View gameView=initializeForView(new MyGame(this), config);
RelativeLayout.LayoutParams gameViewParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
gameViewParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
gameViewParams.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE);
gameView.setLayoutParams(gameViewParams);
layout.addView(gameView);
ad=new ChartBoostHelper(this);
ad.embedView(layout);
setContentView(layout);
@Override
public void onResume() {
super.onResume();
ad.resume();
}
@Override
public void onPause() {
ad.pause();
super.onPause();
}
@Override
public void onDestroy() {
ad.destroy();
super.onDestroy();
}
@Override
protected void onStart() {
super.onStart();
ad.start();
}
@Override
protected void onStop() {
super.onStop();
ad.stop();
}
@Override
public void showOrLoadInterstitial() {
ad.showOrLoadInterstitial();
}
@Override
public boolean showVideoAd(boolean isRewarded) {
return ad.showVideoAd(isRewarded);
}
@Override
protected void onActivityResult (int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
}
}
这是core / ActionResolver.java
public interface ActionResolver {
void showOrLoadInterstitial();
boolean showVideoAd(boolean isRewarded);
}
这是我称之为showOrLoadInterstitial()的部分;在core / GameScreen.java内部的render方法中
if((touchPos.x >= camera.position.x-(replaybutton.getWidth()/2 + 50) && touchPos.x <= (camera.position.x - (replaybutton.getWidth()/2 + 50))+replaybutton.getWidth()) && (touchPos.y>=55 && touchPos.y<=55+replaybutton.getHeight())){
if(SplashScreen.adcount >= 4 && prefs.getBoolean("ADBLOCK") == false){
game.actionResolver.showOrLoadInterstitial();
SplashScreen.adcount = 0;
}
game.setScreen(new MainMenu(game,this.asset));
dispose();
}
这是我的AndroidManifest.xml文件
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.robot1gamesfree.game"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="23" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/GdxTheme" >
<activity
android:name="com.robot1gamesfree.game.AndroidLauncher"
android:label="@string/app_name"
android:screenOrientation="sensorLandscape"
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 android:name="com.chartboost.sdk.CBImpressionActivity"
android:excludeFromRecents="true"
android:hardwareAccelerated="true"
android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen"
android:configChanges="keyboardHidden|orientation|screenSize" />
</activity>
</application>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="com.android.vending.BILLING" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</manifest>