无法在我的Android应用中加载下一个广告(刷新)Flurry Native Ads

时间:2018-12-25 06:49:23

标签: android native flurry

我正在尝试在Android应用中实施Flurry的原生广告。我目前正在设法 显示原生广告。 问题是,在Flurry记录了当前广告展示之后,我无法让它显示下一个原生广告。

Flurry伪支持表示无法将广告配置为刷新自身,因此开发人员需要 编写周转代码以显示下一个原生广告。显示第一个Flurry原生广告的代码是:

private FlurryAdNative mFlurryAdNative = null;
private static final String AD_ASSET_SUMMARY = "summary";
private static final String AD_ASSET_HEADLINE = "headline";
private static final String AD_ASSET_SOURCE = "source";
private static final String AD_ASSET_SEC_HQ_BRANDING_LOGO = "secHqBrandingLogo";
private static final String AD_ASSET_SEC_HQ_RATING_IMAGE = "secHqRatingImg";
private static final String AD_ASSET_SHOW_RATING = "showRating";
private static final String AD_ASSET_SEC_HQ_IMAGE = "secHqImage";
private static final String AD_ASSET_SEC_IMAGE = "secImage";
private static final String AD_ASSET_VIDEO_URL = "videoUrl";

    final TextView adSourceTxt = (TextView)findViewById(R.id.ad_source);
    final TextView adHeadlineTxt = (TextView)findViewById(R.id.ad_headline);
    final TextView adDescription = (TextView)findViewById(R.id.ad_description);
    final ViewGroup adVideo = (ViewGroup)findViewById(R.id.ad_video);
    final ImageView adImage = (ImageView)findViewById(R.id.ad_image);
    final ImageView adSponsorImg = (ImageView)findViewById(R.id.sponsored_image);
    final ImageView adAppRatingImg = (ImageView)findViewById(R.id.app_rating_image);

    mFlurryAdNative = new FlurryAdNative(this, mAdSpaceName);

    // allow us to get callbacks for ad events
    FlurryAdNativeListener nativeListener = new FlurryAdNativeListener() {

        //This method will be called when the ad has been received from the server
        @Override
        public void onFetched(FlurryAdNative adNative) {
            // for instance, you can parse the adNative for the assets returned and create the view to display the ad
            adNative.getAsset(AD_ASSET_SOURCE).loadAssetIntoView(adSourceTxt);
            adNative.getAsset(AD_ASSET_HEADLINE).loadAssetIntoView(adHeadlineTxt);
            adNative.getAsset(AD_ASSET_SUMMARY).loadAssetIntoView(adDescription);
            if (adNative.isVideoAd()) {
                adNative.getAsset(AD_ASSET_VIDEO_URL).loadAssetIntoView(adVideo);
            }
            if (adNative.getAsset(AD_ASSET_SEC_HQ_IMAGE) != null) {
                adNative.getAsset(AD_ASSET_SEC_HQ_IMAGE).loadAssetIntoView(adImage);
            } else if (adNative.getAsset(AD_ASSET_SEC_IMAGE) != null) {
                adNative.getAsset(AD_ASSET_SEC_IMAGE).loadAssetIntoView(adImage);
            }
            adNative.getAsset(AD_ASSET_SEC_HQ_BRANDING_LOGO).loadAssetIntoView(adSponsorImg);
            if (adNative.getAsset(AD_ASSET_SHOW_RATING) != null &&
                    adNative.getAsset(AD_ASSET_SHOW_RATING).equals("true")) {
                adNative.getAsset(AD_ASSET_SEC_HQ_RATING_IMAGE).loadAssetIntoView(adAppRatingImg);
            }

            adNative.setTrackingView(adLayout); //required to support ad tracking
        }

        //This method will be called when there is failure with fetch, render or click.
        @Override
        public void onError(FlurryAdNative adNative, FlurryAdErrorType adErrorType, int errorCode) {
            if (adErrorType.equals(FlurryAdErrorType.FETCH)) {
                //Log.i(kLogTag, "onFetchFailed " + errorCode);
                // you can deploy internal logic to determine whether to  fetch another ad here or not.
                // do not fetch more than x times in a row
            }
        }

        @Override
        public void onCloseFullscreen(FlurryAdNative adNative) {
            //Log.i(kLogTag, "onCloseFullscreen " );
        }

        @Override
        public void onShowFullscreen(FlurryAdNative adNative) {
            //Log.i(kLogTag, "onShowFullscreen " );
        }

        @Override
        public void onExpanded(FlurryAdNative adNative) {
            //Log.i(kLogTag, "onExpanded " );
        }

        @Override
        public void onAppExit(FlurryAdNative adNative) {
            ///Log.i(kLogTag, "onAppExit " );
        }

        @Override
        public void onCollapsed(FlurryAdNative adNative) {
            //Log.i(kLogTag, "onCollapsed " );
        }

        @Override
        public void onImpressionLogged(FlurryAdNative adNative) {
            //Log.i(kLogTag, "onImpressionLogged " );
            adNative.removeTrackingView();
            adNative.destroy(); // Not working to remove current view. Then how?
            adNative.fetchAd();
        }

        @Override
        public void onClicked(FlurryAdNative adNative) {
            //Log.i(kLogTag, "onClicked " );
        }

    };
    mFlurryAdNative.setListener(nativeListener);
    mFlurryAdNative.fetchAd();
注册广告后,

onImpressionLogged(FlurryAdNative adNative)触发, onFetched(FlurryAdNative adNative )触发 当要显示的广告已提取并等待内存时,它也可以正常工作。因此,我尝试清除当前的原生广告 在onImpressionLogged函数中。可以尝试的事情:

adNative.removeTrackingView(); // Just unlinks the ad with the Flurry tracking
adNative.destroy(); // Not working to remove current view. Then how?
adNative.fetchAd(); // Would go to fetch the next ad, but the current ad is still displayed

请注意, loadAssetIntoView 是FlurryAdNative对象的专有功能,用于附加ViewGroup,ImageView或TextView。但是FlurryAdNative没有任何撤消此类附件的指令。那么,如何擦除或分离作为原生广告接收者的视图呢?有任何想法吗?谢谢。

0 个答案:

没有答案