Chartboost ads not working in libgdx project

255 Views Asked by At

Hi I'm integrating Chartboost in my game but the ads aren't showing in live and testing mode. I followed this tutorial in exact manner and there is no error in my code https://github.com/itsabhiaryan/AdService-LibGDX

In https://github.com/itsabhiaryan/AdService-LibGDX/blob/master/android/src/com/its/adservice/AndroidLauncher.java line 34 I changed to ad=new ChartBoostHelper(this); I removed the onSaveInstanceState and onRestoreInstanceState methods and also I made other changes. I called the show ads method in the right place but it does not show.

I registered Chartboost and added my appId and signature accordingly and also set the setting to landscape and interstitial ads. I have modified the AndroidManifest file as in the tutorial and added the jar file in /android/libs folder. Am I missing something or doing something wrong?

This is my android/AndroidLauncher.java and the ChartBoostHelper and the Ad class is the same as in the github link.

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);
    }
}

This is the core/ActionResolver.java

public interface ActionResolver {

    void showOrLoadInterstitial();
    boolean showVideoAd(boolean isRewarded);
}

This is the part where I call showOrLoadInterstitial(); in the render method inside of core/GameScreen.java

        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();
        }

Here is my AndroidManifest.xml file

<?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>
0

There are 0 best solutions below