Smaato interstitial ads not loading up in my android app

568 Views Asked by At

I have tried integrating interstitial ads according to these docs given on their website. But ads are not loading up.

This is my code,

import android.content.Intent
import android.content.pm.PackageManager
import android.os.AsyncTask
import android.os.Build
import android.os.Bundle
import android.preference.PreferenceManager
import android.util.Log
import android.view.View
import android.widget.Button
import androidx.annotation.NonNull
import androidx.appcompat.app.AppCompatActivity
import com.smaato.sdk.core.Config
import com.smaato.sdk.core.SmaatoSdk
import com.smaato.sdk.core.log.LogLevel
import com.smaato.sdk.interstitial.EventListener
import com.smaato.sdk.interstitial.Interstitial
import com.smaato.sdk.interstitial.InterstitialAd
import com.smaato.sdk.interstitial.InterstitialError
import com.smaato.sdk.interstitial.InterstitialRequestError
import kotlinx.android.synthetic.main.activity_download_page.*

class DownloadPageActivity : AppCompatActivity() {

    private val TAG = "DownloadPageActivity"
    lateinit var bannerView: BannerView
    lateinit var newspaperList: NewspaperList
    lateinit var tagOfCardClicked: String
    lateinit var pdfLinks: MutableList<String>
    lateinit var dates: MutableList<String>
    lateinit var date: Date
    var tagOfButtonClicked: Int = 0
    var result: String = ""

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        /*val config: Config = Config.builder() // log errors only
            .setLogLevel(LogLevel.ERROR) // allow HTTPS traffic only
            .setHttpsOnly(true)
            .build()
        SmaatoSdk.init(application, config, "1100046327")
        SmaatoSdk.setGPSEnabled(true)*/

        setContentView(R.layout.activity_download_page)

        newspaperList = NewspaperList()
        pdfLinks = mutableListOf()
        dates = mutableListOf()

        val bundle = intent.extras
        tagOfCardClicked = bundle!!.getString("card_clicked")!!

        title_text_downloadpage.text = newspaperList.getNewspaper(tagOfCardClicked.toInt()).title
    }

    fun buttonClicked(view: View) {
        tagOfButtonClicked = Integer.parseInt(view.tag.toString())
        println("Button clicked + ${view.resources.getResourceName(view.id)}")

        Interstitial.loadAd("130626426", eventListener)
    }

    val eventListener = object : EventListener {
        override fun onAdImpression(p0: InterstitialAd) {
            Log.i(TAG, "onAdImpression-> $p0 ")
        }

        override fun onAdTTLExpired(p0: InterstitialAd) {
            Log.i(TAG, "onAdTTLExpired-> $p0 ")
        }

        override fun onAdClicked(p0: InterstitialAd) {
            Log.i(TAG, "onAdClicked-> $p0 ")
        }

        override fun onAdFailedToLoad(p0: InterstitialRequestError) {
            Log.i(TAG, "onAdFailedToLoad -> $p0")
        }

        override fun onAdLoaded(@NonNull interstitialAd: InterstitialAd) {
            Log.i(TAG, "Interstitial ad loaded")
            interstitialAd.setBackgroundColor(-0xedcbaa)
            interstitialAd.showAd(DownloadPageActivity())
        }

        override fun onAdOpened(p0: InterstitialAd) {
            Log.i(TAG, "onAdOpened-> $p0 ")
        }

        override fun onAdClosed(p0: InterstitialAd) {
            val intent = Intent(applicationContext, WebViewActivity::class.java)
            intent.putExtra("pdf_link", pdfLinks[tagOfButtonClicked - 1])
            Log.i(TAG, "onAdClosed-> $p0 ")
            startActivity(intent)
        }

        override fun onAdError(p0: InterstitialAd, p1: InterstitialError) {
            Log.i(TAG, "onAdError-> $p0 ")
        }
    }
}

This is the log report I am getting,

I/DownloadPageActivity: onAdFailedToLoad -> com.smaato.sdk.interstitial.InterstitialRequestError@d7e0f16

I am using test ID to load the ads. I have tried to load ads on emulator as well as a real device but no progress. I cant find any articles, tutorials, blogs, anything related to this error.

1

There are 1 best solutions below

0
On

Kindly check the error code in onAdFailedToLoad:

public void onAdFailedToLoad(@NonNull InterstitialRequestError interstitialRequestError) {
            Timber.e("InterstitialAd -> onAdFailedToLoad -> interstitialRequestError : "+interstitialRequestError.getInterstitialError());
            
        }

what error message you are getting in onAdFailedToLoad?

interstitialRequestError : [NO_AD_AVAILABLE]: No ad is currently available matching the requested parameters. Please try again later.

Above error message is showing fillrate is 0 now, but implementation don't has any issue. Ads could be load later at some point.

Note: Ads Fill Rate depends on users traffic in case of some ads service providers.

Or

What you can do check your implementation by testing units

  • Change Publisher ID with test publisher Id

  • Ads unit with test ads Id

    public class SmaatoConfig {

     public static boolean ADS_ENABLE = true;
    
     private static String LIVE_PUBLISHER_ID = "Your...";
     private static String LIVE_BANNER_ID = "Your...";
     private static String LIVE_INTERSTITIAL_ID_SKIP = "Your...";
     private static String LIVE_INTERSTITIAL_ID_NON_SKIP = "Your...";
    
     private static String TEST_PUBLISHER_ID = "SMAATO_PUBLISHER_ID";
     private static String TEST_BANNER_ID_RICH_MEDIA = "130626424"; //Banner / Med-rect / Leaderboard / Skyscraper
     private static String TEST_BANNER_ID_STATIC_IMAGE = "130635694"; //Banner / Med-rect / Leaderboard / Skyscraper
     private static String TEST_BANNER_ID_MARID = "130635706"; //Banner / Med-rect / Leaderboard / Skyscraper
     private static String TEST_BANNER_ID_RICH_MEDIA_VIDEO = "130626426"; //Interstitial (Video with an end-card + Rich Media Interstitial for 320×480, 480×320, 1024×768 & 768×1024)
     private static String TEST_VIDEO_ID = "130626427"; //Skippable Video
     private static String TEST_REWARDED_ID = "130626428"; //Rewarded Video
     private static String TEST_REWARDED_WITH_OUT_END_CARD_ID = "130635048"; //Rewarded Video without an end-card
     private static String TEST_Native_ID = "130783664"; //Native with static image main creative
    
    
     //===============================================
    
     //Live Only
     /*public static String PUBLISHER_ID = LIVE_PUBLISHER_ID;
     public static String BANNER_ID = LIVE_BANNER_ID;
     public static String INTERSTITIAL_ID_SKIP = LIVE_INTERSTITIAL_ID_SKIP;
     public static String INTERSTITIAL_ID_NON_SKIP = LIVE_INTERSTITIAL_ID_NON_SKIP;*/
    
     //Test Only
     public static String PUBLISHER_ID = TEST_PUBLISHER_ID;
     public static String BANNER_ID = TEST_BANNER_ID_STATIC_IMAGE;
     public static String INTERSTITIAL_ID_SKIP = TEST_VIDEO_ID;
     public static String INTERSTITIAL_ID_NON_SKIP = TEST_REWARDED_WITH_OUT_END_CARD_ID;
    

    }

I hope it will help you. Don't forget to respond on solution if it works for you just add your comment and vote it. So it will be helpfull for others also.

:) all the BEST !