Heyzap Mediation With Vungle In Android Studio

Discussion in 'Technical Discussion' started by itzonator, Jan 11, 2019.

  1. itzonator

    itzonator Serious Boxer

    Joined:
    Dec 18, 2017
    Messages:
    595
    Likes Received:
    230
    For those who are trying to use Vungle as part of HeyZap mediation and by the way here's a video of how to integrate HeyZap Mediation with AppLovin:

    With Vungle is the same process you follow in HeyZap Dashboard, but in code, you have to add something in android's manifest file and it goes like this:

    Instead of Vungle generated default code from BuildBox 2.3.7 (this is no longer working @NikRudenko )
    Code:
    <!-- VUNGLE --><!--
            <activity
                 android:name="com.vungle.publisher.FullScreenAdActivity"
                 android:configChanges="keyboardHidden|orientation|screenSize"
                 android:theme="@android:style/Theme.NoTitleBar.Fullscreen"/>
    --><!-- VUNGLE -->
    That above is no longer in use, if you are using the latest Vungle SDK (vungle-android-sdk-6.3.24.jar) or above, you have to add this to your manifest file instead:

    Code:
    <!--Vungle Activities-->
            <activity
                android:name="com.vungle.warren.ui.VungleActivity"
                android:configChanges="keyboardHidden|orientation|screenSize|screenLayout|smallestScreenSize"
                android:launchMode="singleTop"
                android:theme="@android:style/Theme.NoTitleBar.Fullscreen" />
            <activity
                android:name="com.vungle.warren.ui.VungleFlexViewActivity"
                android:configChanges="keyboardHidden|orientation|screenSize|screenLayout|smallestScreenSize"
                android:hardwareAccelerated="true"
                android:launchMode="singleTop"
                android:theme="@android:style/Theme.Translucent.NoTitleBar" />
            <!--Vungle-->
    And please do not forget to add the following dependencies in build.gradle of the app:
    Code:
        implementation 'com.fyber:fairbid:9.52.0'
    -> That's for HeyZap, no need to implement any Vungle or other 3rd party networks. Heyzap is taking care of that automatically.

    And please do not forget to add the following repository in build.gradle for the project:
    Code:
            google()
            maven { url "https://fyber.bintray.com/fairbid-maven" }
    below the jcenter().

    It should look like this:

    Code:
    allprojects {
        repositories {
            jcenter()
            maven {
                url "https://maven.google.com"
                //  url 'https://jitpack.io'
            }
            google()
            maven { url "https://fyber.bintray.com/fairbid-maven" }
        }
    }
    ** Important: remove the old PTAdHeyzap.jar generated from BuildBox in the app->libs folder, that's an old version of Heyzap, use the latest Heyzap SDK with .aar files. If you do not remove the PTAdHeyzap.jar it will give you a compile error.

    This worked for me, I believe that's not mentioned in the video, since @ZackGriset is talking about integrating just Applovin here.

    Enjoy,
    Itzo

    P.S. If you find this useful, do not forget to LIKE :p
     
    Last edited: Jan 11, 2019
  2. Bryan Allan Talisay

    Bryan Allan Talisay Boxer

    Joined:
    Dec 5, 2018
    Messages:
    15
    Likes Received:
    0
    hello, im using applovin plus heyzap, i download the sdk of Heyzap but there's no .jar file for android. How's that possible? heyzap.png
    I also get this error in my android studio
     

    Attached Files:

  3. Bryan Allan Talisay

    Bryan Allan Talisay Boxer

    Joined:
    Dec 5, 2018
    Messages:
    15
    Likes Received:
    0
    hello,
    what wrong with error? Im using InMobi moneytization. It says that "cannot resolve InterstitialAdListener". somebody can help me?


    package com.secrethq.ads;

    import java.lang.ref.WeakReference;
    import java.util.Map;

    import org.cocos2dx.lib.Cocos2dxActivity;

    import android.util.Log;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.FrameLayout;
    import android.widget.RelativeLayout;

    import com.inmobi.ads.InMobiBanner;
    import com.inmobi.ads.InMobiInterstitial;
    import com.inmobi.sdk.InMobiSdk;
    import com.inmobi.ads.InMobiAdRequestStatus;

    public class PTAdInMobiBridge {
    private static final String TAG = "PTAdInMobiBridge";
    private static WeakReference<Cocos2dxActivity> s_activity;
    private static Cocos2dxActivity activity;

    private static native String accountId();
    private static native long bannerId();
    private static native long interstitialId();

    private static boolean initComplete;
    private static boolean isBannerVisible;

    private static InMobiBanner imbanner;
    private static InMobiInterstitial interstitial;
    private static ViewGroup view;
    private static RelativeLayout.LayoutParams adViewParams;

    private static native void interstitialDidFail();
    private static native void bannerDidFail();

    // the method must be called in main thread, before any other method
    public static void initBridge(Cocos2dxActivity activity){
    Log.v(TAG, "PTAdInMobiBridge --- INIT");
    PTAdInMobiBridge.s_activity = new WeakReference<Cocos2dxActivity>(activity);
    PTAdInMobiBridge.activity = activity;

    initComplete = false;

    PTAdInMobiBridge.s_activity.get().runOnUiThread(new Runnable() {
    public void run() {
    if(PTAdInMobiBridge.accountId() == null){
    return;
    }

    FrameLayout frameLayout = (FrameLayout)PTAdInMobiBridge.activity.findViewById(android.R.id.content);

    float density = PTAdInMobiBridge.activity.getResources().getDisplayMetrics().density;
    int width = Math.round(320 * density);
    int height= Math.round(50 * density);

    adViewParams = new RelativeLayout.LayoutParams( width, height );
    adViewParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    adViewParams.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);

    RelativeLayout layout = new RelativeLayout( PTAdInMobiBridge.activity );
    frameLayout.addView( layout );

    PTAdInMobiBridge.view = layout;

    InMobiSdk.init(PTAdInMobiBridge.activity, PTAdInMobiBridge.accountId());
    initComplete = true;
    }
    });
    }

    public static void hideBanner() {
    if(initComplete == false){
    return;
    }

    isBannerVisible = false;

    Log.v(TAG, "hideBanner() is called...");

    PTAdInMobiBridge.s_activity.get().runOnUiThread(new Runnable() {
    public void run() {
    if ( PTAdInMobiBridge.imbanner != null ){
    PTAdInMobiBridge.imbanner.setVisibility(View.INVISIBLE);
    }
    }
    });
    }

    public static void showBanner() {
    if(initComplete == false){
    return;
    }

    isBannerVisible = true;

    Log.v(TAG, "showBanner() is called...");
    Log.v(TAG, "PTAdInMobiBridge.bannerId() = " + PTAdInMobiBridge.bannerId() );

    PTAdInMobiBridge.s_activity.get().runOnUiThread(new Runnable() {
    public void run() {
    if ( PTAdInMobiBridge.imbanner == null ) {
    PTAdInMobiBridge.imbanner = new InMobiBanner(PTAdInMobiBridge.activity, PTAdInMobiBridge.bannerId());
    PTAdInMobiBridge.imbanner.setListener(new InMobiBanner.BannerAdListener() {

    @Override
    public void onAdLoadSucceeded(InMobiBanner inMobiBanner) {
    Log.w(TAG, "Banner ad load Succeeded ");
    if ( PTAdInMobiBridge.isBannerVisible )
    inMobiBanner.setVisibility(View.VISIBLE);
    }

    @Override
    public void onAdLoadFailed(InMobiBanner inMobiBanner,
    InMobiAdRequestStatus inMobiAdRequestStatus) {
    Log.w(TAG, "Banner ad failed to load with error: " +
    inMobiAdRequestStatus.getMessage());

    bannerDidFail();
    }

    @Override
    public void onAdDisplayed(InMobiBanner inMobiBanner) {
    }

    @Override
    public void onAdDismissed(InMobiBanner inMobiBanner) {
    }

    @Override
    public void onAdInteraction(InMobiBanner inMobiBanner, Map<Object, Object> map) {
    }

    @Override
    public void onUserLeftApplication(InMobiBanner inMobiBanner) {
    }

    @Override
    public void onAdRewardActionCompleted(InMobiBanner inMobiBanner, Map<Object, Object> map) {
    }
    });
    }

    PTAdInMobiBridge.imbanner.setVisibility(View.VISIBLE);

    // adding banner to view only first time
    if ( PTAdInMobiBridge.view.getChildCount() == 0 ) {
    try {
    PTAdInMobiBridge.view.addView( PTAdInMobiBridge.imbanner, PTAdInMobiBridge.adViewParams );
    } catch (Exception e) {
    Log.v(TAG, "showBannerAd - Failed View Add Banner");
    }
    }

    PTAdInMobiBridge.imbanner.load();
    }
    });
    }

    public static void showInterstitial() {
    if(initComplete == false){
    return;
    }

    Log.v(TAG, "showInterstitial() is called...");

    PTAdInMobiBridge.s_activity.get().runOnUiThread(new Runnable() {
    public void run() {
    InMobiInterstitial.InterstitialAdListener interstitialAdListener = new InMobiInterstitial.InterstitialAdListener() {
    @Override
    public void onAdLoadSucceeded(InMobiInterstitial ad) {
    if(ad.isReady()){
    ad.show();
    }
    }
    @Override
    public void onAdLoadFailed(InMobiInterstitial ad, InMobiAdRequestStatus requestStatus) {
    Log.w(TAG, "Interstitial ad failed to load with error: " +
    requestStatus.getMessage());

    interstitialDidFail();
    }
    @Override
    public void onAdDisplayed(InMobiInterstitial ad) {}
    @Override
    public void onAdDismissed(InMobiInterstitial ad) {}
    @Override
    public void onAdInteraction(InMobiInterstitial ad, Map<Object, Object> params) {}
    @Override
    public void onAdRewardActionCompleted(InMobiInterstitial ad, Map<Object, Object> rewards) {}
    @Override
    public void onUserLeftApplication(InMobiInterstitial ad) {}
    };

    if ( PTAdInMobiBridge.interstitial == null ){
    PTAdInMobiBridge.interstitial = new InMobiInterstitial(PTAdInMobiBridge.activity, PTAdInMobiBridge.interstitialId(), interstitialAdListener);
    }
    PTAdInMobiBridge.interstitial.load();
    }
    });
    }
    }
     
  4. Bryan Allan Talisay

    Bryan Allan Talisay Boxer

    Joined:
    Dec 5, 2018
    Messages:
    15
    Likes Received:
    0
    hello, have got this error??

    Program type already present: com.heyzap.house.Manager$1
     
  5. TheGameAppStudio

    TheGameAppStudio Serious Boxer

    Joined:
    Nov 2, 2016
    Messages:
    927
    Likes Received:
    318
    Hi,Click on the Runtask icon to find error and post your logcat details.Can't say anything from code.
     
  6. Bryan Allan Talisay

    Bryan Allan Talisay Boxer

    Joined:
    Dec 5, 2018
    Messages:
    15
    Likes Received:
    0
  7. Bryan Allan Talisay

    Bryan Allan Talisay Boxer

    Joined:
    Dec 5, 2018
    Messages:
    15
    Likes Received:
    0
    does anyone encountered this error using audience network?

    package com.secrethq.ads;
    import java.lang.ref.WeakReference;

    import org.cocos2dx.lib.Cocos2dxActivity;
    import com.facebook.ads.*;

    import android.util.Log;
    import android.view.View;
    import android.widget.FrameLayout;
    import android.widget.RelativeLayout;

    public class PTAdFacebookBridge {
    private static native String bannerId();
    private static native String interstitialId();
    private static native void interstitialDidFail();
    private static native void bannerDidFail();

    private static final String TAG = "PTAdFacebookBridge";
    private static Cocos2dxActivity activity;
    private static WeakReference<Cocos2dxActivity> s_activity;
    private static RelativeLayout layout;
    private static AdView adView;
    private static InterstitialAd interstitialAd;

    private static boolean isBannerScheduledForShow = false;
    private static boolean isInterstitialScheduledForShow = false;

    public static void initBridge(Cocos2dxActivity activity) {
    Log.v(TAG, "PTAdFacebookBridge -- INIT");
    PTAdFacebookBridge.s_activity = new WeakReference<Cocos2dxActivity>(activity);
    PTAdFacebookBridge.activity = activity;
    PTAdFacebookBridge.isBannerScheduledForShow = false;

    // AdSettings.addTestDevice("a69bdc92f615c88e90829d30bf7a331b");
    // AdSettings.addTestDevice("8316127659de8b8430d12ca88a2f8667");
    // AdSettings.addTestDevice("9d48673c77cdcd60c2a95f2aaa538fe0");
    PTAdFacebookBridge.initBanner();
    PTAdFacebookBridge.initInterstitial();

    }

    public static void initBanner(){
    PTAdFacebookBridge.s_activity.get().runOnUiThread( new Runnable() {
    public void run() {


    FrameLayout frameLayout = (FrameLayout)PTAdFacebookBridge.activity.findViewById(android.R.id.content);
    PTAdFacebookBridge.layout = new RelativeLayout( PTAdFacebookBridge.activity );
    frameLayout.addView( PTAdFacebookBridge.layout );

    RelativeLayout.LayoutParams adViewParams = new RelativeLayout.LayoutParams(
    AdView.LayoutParams.WRAP_CONTENT,
    AdView.LayoutParams.WRAP_CONTENT);
    adViewParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    adViewParams.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);

    Log.v(TAG,"__ gonna crash" + PTAdFacebookBridge.bannerId());
    PTAdFacebookBridge.adView = new AdView(PTAdFacebookBridge.activity, PTAdFacebookBridge.bannerId(), AdSize.BANNER_HEIGHT_50);
    PTAdFacebookBridge.adView.setLayoutParams(adViewParams);

    PTAdFacebookBridge.adView.setAdListener(new AdListener() {

    @Override
    public void onError(Ad ad, AdError error) {
    if ( !PTAdFacebookBridge.isBannerScheduledForShow )
    return;

    Log.v(TAG,"ERROR with code: "+ error.getErrorMessage());
    PTAdFacebookBridge.bannerDidFail();
    }

    @Override
    public void onAdLoaded(Ad ad) {
    Log.v(TAG,"LOADED");

    if ( PTAdFacebookBridge.isBannerScheduledForShow )
    PTAdFacebookBridge.layout.addView(PTAdFacebookBridge.adView);
    else
    PTAdFacebookBridge.layout.removeView(PTAdFacebookBridge.adView);
    }

    @Override
    public void onAdClicked(Ad ad) {
    Log.v(TAG,"CLICKED");
    // Use this function to detect when an ad was clicked.
    }

    });

    if (!bannerId().isEmpty())
    PTAdFacebookBridge.adView.loadAd();
    }
    });
    }

    public static void initInterstitial(){
    PTAdFacebookBridge.s_activity.get().runOnUiThread( new Runnable() {
    public void run() {


    if(PTAdFacebookBridge.interstitialAd != null){
    PTAdFacebookBridge.interstitialAd.destroy();
    PTAdFacebookBridge.interstitialAd = null;
    }

    PTAdFacebookBridge.interstitialAd = new InterstitialAd(PTAdFacebookBridge.activity, interstitialId());
    PTAdFacebookBridge.interstitialAd.setAdListener(new InterstitialAdListener() {

    @Override
    public void onError(Ad ad, AdError error) {
    if ( !isInterstitialScheduledForShow )
    return;

    Log.v(TAG,"interstitial ERROR with code: "+ error.getErrorMessage());
    PTAdFacebookBridge.interstitialDidFail();
    }

    @Override
    public void onAdLoaded(Ad ad) {
    if(PTAdFacebookBridge.isInterstitialScheduledForShow == true){
    PTAdFacebookBridge.interstitialAd.show();
    }

    PTAdFacebookBridge.isInterstitialScheduledForShow = false;
    }

    @Override
    public void onAdClicked(Ad ad) {
    Log.v(TAG,"interstitial CLICKED");
    // Use this function to detect when an ad was clicked.
    }

    @Override
    public void onInterstitialDismissed(Ad arg0) {
    PTAdFacebookBridge.initInterstitial();
    }

    @Override
    public void onInterstitialDisplayed(Ad arg0) {
    PTAdFacebookBridge.isInterstitialScheduledForShow = false;
    }

    });

    if (!interstitialId().isEmpty())
    interstitialAd.loadAd();
    }
    });
    }

    public static void showFullScreen(){
    Log.v(TAG, "showInterstitials");

    isInterstitialScheduledForShow = true;

    PTAdFacebookBridge.s_activity.get().runOnUiThread( new Runnable() {
    public void run() {
    if(PTAdFacebookBridge.interstitialAd.isAdLoaded()){
    PTAdFacebookBridge.interstitialAd.show();
    PTAdFacebookBridge.isInterstitialScheduledForShow = false;
    }
    else{
    PTAdFacebookBridge.isInterstitialScheduledForShow = true;
    }
    }
    });
    }


    public static void showBannerAd(){
    Log.v(TAG, "showBannerAd");

    PTAdFacebookBridge.isBannerScheduledForShow = true;

    if(PTAdFacebookBridge.adView != null && isBannerVisisble() == false){
    PTAdFacebookBridge.s_activity.get().runOnUiThread( new Runnable() {
    public void run() {
    PTAdFacebookBridge.layout.addView(PTAdFacebookBridge.adView);
    }
    });
    }

    }

    public static void hideBannerAd(){
    Log.v(TAG, "hideBannerAd");

    PTAdFacebookBridge.isBannerScheduledForShow = false;

    if(PTAdFacebookBridge.adView != null){
    PTAdFacebookBridge.s_activity.get().runOnUiThread( new Runnable() {
    public void run() {
    PTAdFacebookBridge.layout.removeView(PTAdFacebookBridge.adView);
    }
    });
    }
    }

    public static boolean isBannerVisisble(){
    if(PTAdFacebookBridge.adView != null){

    if(PTAdFacebookBridge.adView.getParent() != null ){
    return true;
    }
    else{
    return false;
    }
    }
    else{
    return false;
    }
    }


    }
    face.png
     

Share This Page