当前位置: 首页>>代码示例>>Java>>正文


Java NativeMediationAdRequest类代码示例

本文整理汇总了Java中com.google.android.gms.ads.mediation.NativeMediationAdRequest的典型用法代码示例。如果您正苦于以下问题:Java NativeMediationAdRequest类的具体用法?Java NativeMediationAdRequest怎么用?Java NativeMediationAdRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


NativeMediationAdRequest类属于com.google.android.gms.ads.mediation包,在下文中一共展示了NativeMediationAdRequest类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: MyTargetNativeAdListener

import com.google.android.gms.ads.mediation.NativeMediationAdRequest; //导入依赖的package包/类
MyTargetNativeAdListener(final @NonNull NativeAd nativeAd,
                         final @Nullable NativeMediationAdRequest nativeMediationAdRequest,
                         final @NonNull Context context) {
    this.nativeAd = nativeAd;
    this.nativeMediationAdRequest = nativeMediationAdRequest;
    this.context = context;
}
 
开发者ID:googleads,项目名称:googleads-mobile-android-mediation,代码行数:8,代码来源:MyTargetNativeAdapter.java

示例2: requestNativeAd

import com.google.android.gms.ads.mediation.NativeMediationAdRequest; //导入依赖的package包/类
@Override
public void requestNativeAd(Context context,
                            MediationNativeListener listener,
                            Bundle serverParameters,
                            NativeMediationAdRequest mediationAdRequest,
                            Bundle mediationExtras) {
    mNativeListener = listener;
    if (!isValidRequestParameters(context, serverParameters)) {
        mNativeListener.onAdFailedToLoad(this, AdRequest.ERROR_CODE_INVALID_REQUEST);
        return;
    }

    // Verify that the request is for both app install and content ads.
    if (!(mediationAdRequest.isAppInstallAdRequested()
            && mediationAdRequest.isContentAdRequested())) {
        Log.w(TAG, "Failed to request native ad. Both app install and content ad should be "
                + "requested");
        mNativeListener.onAdFailedToLoad(this, AdRequest.ERROR_CODE_INVALID_REQUEST);
        return;
    }

    String placementId = serverParameters.getString(PLACEMENT_PARAMETER);

    // Get the optional extras if set by the publisher.
    if (mediationExtras != null) {
        mIsAdChoicesIconExpandable = mediationExtras.getBoolean(
                FacebookExtrasBundleBuilder.KEY_EXPANDABLE_ICON, true);
    }

    mMediaView = new MediaView(context);

    mNativeAd = new NativeAd(context, placementId);
    mNativeAd.setAdListener(new NativeListener(mNativeAd, mediationAdRequest));
    buildAdRequest(mediationAdRequest);
    mNativeAd.loadAd();
}
 
开发者ID:googleads,项目名称:googleads-mobile-android-mediation,代码行数:37,代码来源:FacebookAdapter.java

示例3: requestNativeAd

import com.google.android.gms.ads.mediation.NativeMediationAdRequest; //导入依赖的package包/类
/**
 * Implementation of CustomEventNative interface.
 * Delegates the banner ad call to Smart AdServer SDK
 */
@Override
public void requestNativeAd(final Context context, final CustomEventNativeListener customEventNativeListener, String s, NativeMediationAdRequest nativeMediationAdRequest, Bundle bundle) {
    // get smart placement object
    SASCustomEventUtil.SASAdPlacement adPlacement = SASCustomEventUtil.getPlacementFromString(s,nativeMediationAdRequest);

    if (adPlacement == null) {
        // incorrect smart placement : exit in error
        customEventNativeListener.onAdFailedToLoad(AdRequest.ERROR_CODE_INVALID_REQUEST);
    } else {
        if (sasNativeAdManager == null) {
            // instantiate the AdResponseHandler to handle Smart ad call outcome
            nativeAdResponseHandler = new SASNativeAdManager.NativeAdResponseHandler() {
                @Override
                public void nativeAdLoadingCompleted(SASNativeAdElement nativeAdElement) {

                    // TODO native ad mapper
                    NativeAdMapper adMapper = new NativeAdMapper() {
                    };
                    customEventNativeListener.onAdLoaded(adMapper);

                    nativeAdElement.setClickHandler(new SASNativeAdElement.ClickHandler() {

                        @Override
                        public boolean handleClick(String clickUrl, SASNativeAdElement nativeAdElement) {
                            customEventNativeListener.onAdClicked();
                            customEventNativeListener.onAdOpened();
                            customEventNativeListener.onAdLeftApplication();
                            return false;
                        }
                    });
                }

                @Override
                public void nativeAdLoadingFailed(Exception e) {
                    int errorCode = AdRequest.ERROR_CODE_INTERNAL_ERROR;
                    if (e instanceof SASNoAdToDeliverException) {
                        // no ad to deliver
                        errorCode = AdRequest.ERROR_CODE_NO_FILL;
                    } else if (e instanceof SASAdTimeoutException) {
                        // ad request timeout translates to admob network error
                        errorCode = AdRequest.ERROR_CODE_NETWORK_ERROR;
                    }
                    customEventNativeListener.onAdFailedToLoad(errorCode);
                }
            };

            SASNativeAdPlacement nativeAdPlacement = new SASNativeAdPlacement(SASConstants.DEFAULT_BASE_URL,
                    adPlacement.siteId,adPlacement.pageId,adPlacement.formatId,adPlacement.targeting);

            // instantiate SASNativeAdManager that will perform the Smart ad call
            sasNativeAdManager = new SASNativeAdManager(context,nativeAdPlacement);


            // pass received location on to SASNativeAdManager
            sasNativeAdManager.setLocation(nativeMediationAdRequest.getLocation());

            // Now request ad for this SASNativeAdManager
            sasNativeAdManager.requestNativeAd(nativeAdResponseHandler,10000);
        }
    }
}
 
开发者ID:smartadserver,项目名称:SAS-DFP-Adapter-Android,代码行数:66,代码来源:SASCustomEventNative.java

示例4: requestNativeAd

import com.google.android.gms.ads.mediation.NativeMediationAdRequest; //导入依赖的package包/类
@Override
public void requestNativeAd(@Nullable Context context,
							@Nullable CustomEventNativeListener customEventNativeListener,
							@Nullable String serverParameter,
							@Nullable NativeMediationAdRequest nativeMediationAdRequest,
							@Nullable
									Bundle customEventExtras)
{
	if (context == null)
	{
		Log.d(TAG, "unable to request native ad, context is null");
		if (customEventNativeListener != null)
		{
			customEventNativeListener.onAdFailedToLoad(AdRequest.ERROR_CODE_INTERNAL_ERROR);
		}
		return;
	}

	this.resources = context.getResources();

	this.customEventNativeListener = customEventNativeListener;

	NativeAdOptions options = null;
	int gender = 0;
	Date birthday = null;
	if (nativeMediationAdRequest != null)
	{
		options = nativeMediationAdRequest.getNativeAdOptions();
		isAppInstallAdRequested = nativeMediationAdRequest.isAppInstallAdRequested();
		isContentAdRequested = nativeMediationAdRequest.isContentAdRequested();
		gender = nativeMediationAdRequest.getGender();
		birthday = nativeMediationAdRequest.getBirthday();
	}

	int slotId;
	try
	{
		JSONObject json = new JSONObject(serverParameter);
		slotId = json.getInt(SLOT_ID_KEY);
	} catch (Exception e)
	{
		Log.i(TAG, "Unable to get slotId from parameter json. Probably Admob mediation misconfiguration.");
		if (customEventNativeListener != null)
		{
			customEventNativeListener.onAdFailedToLoad(AdRequest.ERROR_CODE_INTERNAL_ERROR);
		}
		return;
	}

	NativeAd nativeAd = new NativeAd(slotId, context.getApplicationContext());

	if (options != null)
	{
		nativeAd.setAutoLoadImages(!options.shouldReturnUrlsForImageAssets());
	}

	nativeAd.getCustomParams().setGender(gender);

	if (birthday != null && birthday.getTime() != -1)
	{
		GregorianCalendar calendar = new GregorianCalendar();
		GregorianCalendar calendarNow = new GregorianCalendar();

		calendar.setTimeInMillis(birthday.getTime());
		int a = calendarNow.get(GregorianCalendar.YEAR) - calendar.get(GregorianCalendar.YEAR);
		if (a >= 0)
		{
			nativeAd.getCustomParams().setAge(a);
		}
	}

	nativeAd.getCustomParams().setCustomParam("mediation", "1");
	nativeAd.setListener(nativeAdListener);
	nativeAd.load();
}
 
开发者ID:myTargetSDK,项目名称:mytarget-android,代码行数:76,代码来源:MyTargetAdmobCustomEventNative.java

示例5: requestNativeAd

import com.google.android.gms.ads.mediation.NativeMediationAdRequest; //导入依赖的package包/类
@Override
public void requestNativeAd(Context context,
                            CustomEventNativeListener customEventNativeListener,
                            String serverParameter,
                            NativeMediationAdRequest nativeMediationAdRequest,
                            Bundle extras) {
    // Create one of the Sample SDK's ad loaders from which to request ads.
    SampleNativeAdLoader loader = new SampleNativeAdLoader(context);
    loader.setAdUnit(serverParameter);

    // Create a native request to give to the SampleNativeAdLoader.
    SampleNativeAdRequest request = new SampleNativeAdRequest();

    // The Google Mobile Ads SDK requires the image assets to be downloaded automatically unless
    // the publisher specifies otherwise by using the NativeAdOptions object's
    // shouldReturnUrlsForImageAssets method. If your network doesn't have an option like this
    // and instead only ever returns URLs for images (rather than the images themselves), your
    // adapter should download image assets on behalf of the publisher. See the
    // SampleNativeMediationEventForwarder for information on how to do so.
    request.setShouldDownloadImages(true);

    request.setShouldDownloadMultipleImages(false);
    request.setPreferredImageOrientation(SampleNativeAdRequest.IMAGE_ORIENTATION_ANY);

    NativeAdOptions options = nativeMediationAdRequest.getNativeAdOptions();

    if (options != null) {
        // If the NativeAdOptions' shouldReturnUrlsForImageAssets is true, the adapter should
        // send just the URLs for the images.
        request.setShouldDownloadImages(!options.shouldReturnUrlsForImageAssets());

        // If your network does not support any of the following options, please make sure
        // that it is documented in your adapter's documentation.
        request.setShouldDownloadMultipleImages(options.shouldRequestMultipleImages());
        switch (options.getImageOrientation()) {
            case NativeAdOptions.ORIENTATION_LANDSCAPE:
                request.setPreferredImageOrientation(
                        SampleNativeAdRequest.IMAGE_ORIENTATION_LANDSCAPE);
                break;
            case NativeAdOptions.ORIENTATION_PORTRAIT:
                request.setPreferredImageOrientation(
                        SampleNativeAdRequest.IMAGE_ORIENTATION_PORTRAIT);
                break;
            case NativeAdOptions.ORIENTATION_ANY:
            default:
                request.setPreferredImageOrientation(
                        SampleNativeAdRequest.IMAGE_ORIENTATION_ANY);
        }
    }

    // Set App Install and Content Ad requests.
    //
    // NOTE: Care needs to be taken to make sure the custom event respects the publisher's
    // wishes in regard to native ad formats. For example, if the mediated ad network only
    // provides app install ads, and the publisher requests content ads alone, the custom event
    // must report an error by calling the listener's onAdFailedToLoad method with an error code
    // of AdRequest.ERROR_CODE_INVALID_REQUEST. It should *not* request an app install ad
    // anyway, and then attempt to map it to the content ad format.
    if (!nativeMediationAdRequest.isAppInstallAdRequested()
            && !nativeMediationAdRequest.isContentAdRequested()) {
        customEventNativeListener.onAdFailedToLoad(AdRequest.ERROR_CODE_INVALID_REQUEST);
        return;
    }
    request.setAppInstallAdsRequested(nativeMediationAdRequest.isAppInstallAdRequested());
    request.setContentAdsRequested(nativeMediationAdRequest.isContentAdRequested());

    loader.setNativeAdListener(
            new SampleCustomNativeEventForwarder(customEventNativeListener, options));

    // Begin a request.
    loader.fetchAd(request);
}
 
开发者ID:googleads,项目名称:googleads-mobile-android-mediation,代码行数:73,代码来源:SampleCustomEvent.java

示例6: requestNativeAd

import com.google.android.gms.ads.mediation.NativeMediationAdRequest; //导入依赖的package包/类
@Override
public void requestNativeAd(Context context,
                            MediationNativeListener customEventNativeListener,
                            Bundle serverParameter,
                            NativeMediationAdRequest nativeMediationAdRequest,
                            Bundle customEventExtras) {
    this.customEventNativeListener = customEventNativeListener;
    int slotId = MyTargetTools.checkAndGetSlotId(context, serverParameter);
    Log.d(TAG, "Requesting myTarget mediation, slotId: " + slotId);

    if (slotId < 0) {
        if (customEventNativeListener != null) {
            customEventNativeListener.onAdFailedToLoad(
                    MyTargetNativeAdapter.this, AdRequest.ERROR_CODE_INVALID_REQUEST);
        }
        return;
    }
    NativeAdOptions options = null;
    int gender = 0;
    Date birthday = null;
    boolean contentRequested = false;
    boolean installRequested = false;
    if (nativeMediationAdRequest != null) {
        options = nativeMediationAdRequest.getNativeAdOptions();
        gender = nativeMediationAdRequest.getGender();
        birthday = nativeMediationAdRequest.getBirthday();
        contentRequested = nativeMediationAdRequest.isContentAdRequested();
        installRequested = nativeMediationAdRequest.isAppInstallAdRequested();
    }

    NativeAd nativeAd = new NativeAd(slotId, context);

    boolean autoLoadImages = true;
    if (options != null) {
        autoLoadImages = !options.shouldReturnUrlsForImageAssets();
        Log.d(TAG, "Set autoload images to " + autoLoadImages);
    }
    nativeAd.setAutoLoadImages(autoLoadImages);

    CustomParams params = nativeAd.getCustomParams();
    Log.d(TAG, "Set gender to " + gender);
    params.setGender(gender);

    if (birthday != null && birthday.getTime() != -1) {
        GregorianCalendar calendar = new GregorianCalendar();
        GregorianCalendar calendarNow = new GregorianCalendar();

        calendar.setTimeInMillis(birthday.getTime());
        int age = calendarNow.get(GregorianCalendar.YEAR)
                - calendar.get(GregorianCalendar.YEAR);
        if (age >= 0) {
            params.setAge(age);
        }
    }
    Log.d(TAG, "Content requested: " + contentRequested
            + ", install requested: " + installRequested);
    if (!contentRequested || !installRequested) {
        if (!contentRequested) {
            params.setCustomParam(PARAM_NATIVE_TYPE_REQUEST, PARAM_INSTALL_ONLY);
        } else {
            params.setCustomParam(PARAM_NATIVE_TYPE_REQUEST, PARAM_CONTENT_ONLY);
        }
    }

    MyTargetNativeAdListener nativeAdListener =
            new MyTargetNativeAdListener(nativeAd, nativeMediationAdRequest, context);

    params.setCustomParam(
            MyTargetTools.PARAM_MEDIATION_KEY, MyTargetTools.PARAM_MEDIATION_VALUE);
    nativeAd.setListener(nativeAdListener);
    nativeAd.load();
}
 
开发者ID:googleads,项目名称:googleads-mobile-android-mediation,代码行数:73,代码来源:MyTargetNativeAdapter.java

示例7: NativeListener

import com.google.android.gms.ads.mediation.NativeMediationAdRequest; //导入依赖的package包/类
private NativeListener(NativeAd nativeAd, NativeMediationAdRequest mediationAdRequest) {
    mNativeAd = nativeAd;
    mMediationAdRequest = mediationAdRequest;
}
 
开发者ID:googleads,项目名称:googleads-mobile-android-mediation,代码行数:5,代码来源:FacebookAdapter.java


注:本文中的com.google.android.gms.ads.mediation.NativeMediationAdRequest类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。