Heyzap Button一直在消失

时间:2016-06-03 19:49:07

标签: android admob ads heyzap

我试图制作能够提供100枚硬币的广告。并且按钮在0-2秒后消失。

我不知道为什么会出现此错误。有人知道如何解决这个问题吗?

我的错误

    06-03 21:42:16.017: V/PTAdHeyzapBridge(27950): PTAdHeyzapBridge -- Start Session: "MyHeyzapID"
    06-03 21:42:16.023: E/Heyzap(27950): Heyzap encountered a runtime exception and is now disabled. Error: Attempt to invoke virtual method 'java.lang.String android.content.Context.getPackageName()' on a null object reference
    06-03 21:42:16.023: V/PTAdHeyzapBridge(27950): PTAdHeyzapBridge -- Start Session FAILED : Attempt to invoke virtual method 'java.lang.String android.content.Context.getPackageName()' on a null object reference
    06-03 21:42:16.023: V/PTAdHeyzapBridge(27950): Heyzap SDK Version : 8.4.1

我的PTAdHeyzapBridge.java

package com.secrethq.ads;

import java.lang.ref.WeakReference;

import org.cocos2dx.lib.Cocos2dxActivity;

import com.google.android.gms.ads.AdView;
import com.heyzap.sdk.ads.HeyzapAds;
import com.heyzap.sdk.ads.InterstitialAd;
import com.heyzap.sdk.ads.VideoAd;
import com.heyzap.sdk.ads.IncentivizedAd;
import com.heyzap.sdk.ads.BannerAdView;
import com.heyzap.sdk.ads.HeyzapAds.BannerListener;
import com.heyzap.sdk.ads.HeyzapAds.BannerError;
import com.heyzap.sdk.ads.HeyzapAds.OnStatusListener;
import com.heyzap.sdk.ads.HeyzapAds.OnIncentiveResultListener;

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

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

    private static final String TAG = "PTAdHeyzapBridge";
    private static Cocos2dxActivity activity;
    private static WeakReference<Cocos2dxActivity> s_activity;
    private static  BannerAdView bannerAdView;

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

        PTAdHeyzapBridge.initBanner();
        PTAdHeyzapBridge.initInterstitial();
        PTAdHeyzapBridge.initVideo();
    }

    public static void initBanner(){
        Log.v(TAG, "PTAdHeyzapBridge -- Init Banner");

        PTAdHeyzapBridge.s_activity.get().runOnUiThread( new Runnable() {
            public void run() {
                PTAdHeyzapBridge.bannerAdView = new BannerAdView(PTAdHeyzapBridge.activity);

                FrameLayout frameLayout = (FrameLayout)PTAdHeyzapBridge.activity.findViewById(android.R.id.content);
                RelativeLayout layout = new RelativeLayout( PTAdHeyzapBridge.activity );
                frameLayout.addView( 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);

                layout.addView(PTAdHeyzapBridge.bannerAdView, adViewParams);
                PTAdHeyzapBridge.bannerAdView.setVisibility( View.INVISIBLE );

                // Add a listener.
                PTAdHeyzapBridge.bannerAdView.setBannerListener(new BannerListener() {
                    @Override
                    public void onAdClicked(BannerAdView b) {
                        // The ad has been clicked by the user.
                    }

                    @Override
                    public void onAdLoaded(BannerAdView b) {
                        // The ad has been loaded.
                    }

                    @Override
                    public void onAdError(BannerAdView b, BannerError bannerError) {
                        // There was an error loading the ad.
                        Log.v(TAG, "PTAdHeyzapBridge -- Banner onAdError : " + bannerError.getErrorMessage());
                        bannerDidFail();
                    }
                });
            }
        });
    }

    public static void initInterstitial(){
        Log.v(TAG, "PTAdHeyzapBridge -- Init Interstitial");        

        InterstitialAd.setOnStatusListener(new OnStatusListener() {
            @Override
            public void onShow(String tag) {
                // Ad is now showing
            }

            @Override
            public void onClick(String tag) {
                // Ad was clicked on. You can expect the user to leave your application temporarily.
            }

            @Override
            public void onHide(String tag) {
                // Ad was closed. The user has returned to your application.
            }

            @Override
            public void onFailedToShow(String tag) {
                // Display was called but there was no ad to show
            }

            @Override
            public void onAvailable(String tag) {
                // An ad has been successfully fetched
            }

            @Override
            public void onFailedToFetch(String tag) {
                // No ad was able to be fetched
                Log.v(TAG, "PTAdHeyzapBridge -- Interstitial onFailedToFetch : " + tag);
                interstitialDidFail();
            }

            @Override
            public void onAudioFinished() {
                // TODO Auto-generated method stub

            }

            @Override
            public void onAudioStarted() {
                // TODO Auto-generated method stub

            }
        });

    }

    public static void initVideo() {
        IncentivizedAd.setOnIncentiveResultListener(new OnIncentiveResultListener() {
            @Override
            public void onComplete(String tag) {
                Log.v(TAG, "PTAdHeyzapBridge -- IncentivizedAd Complete ");

                // Give the player their reward
                rewardVideoComplete();
            }

            @Override
            public void onIncomplete(String tag) {
                // Don't give the player their reward, and tell them why
                Log.v(TAG, "PTAdHeyzapBridge -- IncentivizedAd InComplete ");
            }
        });

        PTAdHeyzapBridge.s_activity.get().runOnUiThread( new Runnable() {
            public void run() {
                // As early as possible, and after showing a rewarded video, call fetch
                IncentivizedAd.fetch();
            }
        });
    }

    public static void showRewardedVideo(){
        Log.v(TAG, "PTAdHeyzapBridge -- showRewardedVideo");

        PTAdHeyzapBridge.s_activity.get().runOnUiThread( new Runnable() {
            public void run() {
                if (IncentivizedAd.isAvailable()) {
                    IncentivizedAd.display(PTAdHeyzapBridge.activity);
                }
            }
        });

    }

    public static void startSession( String sdkKey ){
        if(sdkKey != null){
            Log.v(TAG, "PTAdHeyzapBridge -- Start Session: " + sdkKey);

            try {
                HeyzapAds.start(sdkKey, PTAdHeyzapBridge.activity);
            } catch (Exception e) {
                // TODO: handle exception
                Log.v(TAG, "PTAdHeyzapBridge -- Start Session FAILED : " + e.getMessage());
            }

            Log.v(TAG, "Heyzap SDK Version : " + HeyzapAds.getVersion());

        }else{
            Log.v(TAG, "Start Session : null ");
        }
    }

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

        PTAdHeyzapBridge.s_activity.get().runOnUiThread( new Runnable() {
            public void run() {
                // InterstitialAds are automatically fetched from our server
                InterstitialAd.display(PTAdHeyzapBridge.activity);
            }
        });
    }

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

        PTAdHeyzapBridge.s_activity.get().runOnUiThread( new Runnable() {
            public void run() {
                if(PTAdHeyzapBridge.bannerAdView != null){
                    PTAdHeyzapBridge.bannerAdView.setVisibility(View.VISIBLE);
                    // Load the banner ad.
                    PTAdHeyzapBridge.bannerAdView.load();
                }
            }
        });
    }

    public static void hideBannerAd(){
        Log.v(TAG, "PTAdHeyzapBridge -- hideBannerAd");
        PTAdHeyzapBridge.s_activity.get().runOnUiThread( new Runnable() {
            public void run() {
                if(PTAdHeyzapBridge.bannerAdView != null){
                    PTAdHeyzapBridge.bannerAdView.setVisibility(View.INVISIBLE);
                }
            }
        });
    }

    public static boolean isBannerVisible() {   
        return (PTAdHeyzapBridge.bannerAdView.getVisibility() == View.VISIBLE);
    }

    public static boolean isRewardedVideoAvialable(){   
        return IncentivizedAd.isAvailable();
    }
}

我的主要活动

package com.lopeostudios.runningpanda;

import org.cocos2dx.lib.Cocos2dxActivity;
import org.cocos2dx.lib.Cocos2dxGLSurfaceView;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.WindowManager;
import android.widget.Toast;
import com.secrethq.store.PTStoreBridge;
import com.google.android.gms.games.GamesActivityResultCodes;
import com.lopeostudios.runningpanda.R;
import com.secrethq.ads.*;
import com.secrethq.utils.*;
import com.onesignal.OneSignal;


public class PTPlayer extends Cocos2dxActivity {


    private static native void loadModelController();

    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        Log.v("----------","onActivityResult: request: " + requestCode + " result: "+ resultCode);
        if(PTStoreBridge.iabHelper().handleActivityResult(requestCode, resultCode, data)){
            Log.v("-----------", "handled by IABHelper");
        }
        else if(requestCode == PTServicesBridge.RC_SIGN_IN){
            if(resultCode == RESULT_OK){
                PTServicesBridge.instance().onActivityResult(requestCode, resultCode, data);
            }
            else if(resultCode == GamesActivityResultCodes.RESULT_SIGN_IN_FAILED){
                int duration = Toast.LENGTH_SHORT;
                Toast toast = Toast.makeText(this, "Google Play Services: Sign in error", duration);
                toast.show();
            }
            else if(resultCode == GamesActivityResultCodes.RESULT_APP_MISCONFIGURED){
                int duration = Toast.LENGTH_SHORT;
                Toast toast = Toast.makeText(this, "Google Play Services: App misconfigured", duration);
                toast.show();               
            }
        }
    }

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        OneSignal.startInit(this).init();
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    }



    @Override
    public void onNativeInit(){
            initBridges();              
    }

    private void initBridges(){
        PTStoreBridge.initBridge( this );
        PTServicesBridge.initBridge(this, getString( R.string.app_id ));

        if (PTJniHelper.isAdNetworkActive("kChartboost")) {
            PTAdChartboostBridge.initBridge(this);
        }

        if (PTJniHelper.isAdNetworkActive("kRevMob")) {
            PTAdRevMobBridge.initBridge(this);
        }

        if (PTJniHelper.isAdNetworkActive("kAdMob") || PTJniHelper.isAdNetworkActive("kFacebook")) {
            PTAdAdMobBridge.initBridge(this);
        }

        if (PTJniHelper.isAdNetworkActive("kAppLovin")) {
            PTAdAppLovinBridge.initBridge(this);
        }

        if (PTJniHelper.isAdNetworkActive("kLeadBolt")) {
            PTAdLeadBoltBridge.initBridge(this);
        }

        if (PTJniHelper.isAdNetworkActive("kVungle")) {
            PTAdVungleBridge.initBridge(this);
        }

        if (PTJniHelper.isAdNetworkActive("kPlayhaven")) {
            PTAdUpsightBridge.initBridge(this);
        }

        if (PTJniHelper.isAdNetworkActive("kMoPub")) {
            PTAdMoPubBridge.initBridge(this);
        }

        if (PTJniHelper.isAdNetworkActive("kFacebook")) {
            PTAdFacebookBridge.initBridge(this);
        }

        if (PTJniHelper.isAdNetworkActive("kHeyzap")) {
            PTAdHeyzapBridge.initBridge(this);
        }

    }



    @Override
    public Cocos2dxGLSurfaceView onCreateView() {
        Cocos2dxGLSurfaceView glSurfaceView = new Cocos2dxGLSurfaceView(this);
        glSurfaceView.setEGLConfigChooser(8, 8, 8, 0, 0, 0);

        return glSurfaceView;
    }

    static {
        System.loadLibrary("player");
    }

    @Override
    protected void onResume() {
        super.onResume();
        if (PTJniHelper.isAdNetworkActive("kChartboost")) {
            PTAdChartboostBridge.onResume( this );
        }
    }

    @Override
    protected void onStart() {
        super.onStart();
        if (PTJniHelper.isAdNetworkActive("kChartboost")) {
            PTAdChartboostBridge.onStart( this );
        }
    }

    @Override
    protected void onStop() {
        super.onStop();
        if (PTJniHelper.isAdNetworkActive("kChartboost")) {
            PTAdChartboostBridge.onStop( this );
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }




}

1 个答案:

答案 0 :(得分:0)

我是Heyzap的工程师。我们的SDK将捕获来自第三方SDK的异常,如果我们捕获一个SDK,则关闭我们的SDK(这是防止异常崩溃游戏的最后一道防线)。在这种情况下,我们会抓住这个例外:

06-03 21:42:16.023: E/Heyzap(27950): Heyzap encountered a runtime exception and is now disabled. Error: Attempt to invoke virtual method 'java.lang.String android.content.Context.getPackageName()' on a null object reference

我们之前见过这个由过时的UnityAds SDK引起的异常。您使用的是网络吗?如果是,您可以试试UnityAds 1.5.6吗?如果你不是,你能告诉我们你正在使用哪些网络,或者游戏的Android套餐吗?

另外,我在你的日志中看到你正在使用去年6月发布的Heyzap 8.4.1。你能更新到我们的最新版本吗?