本文整理汇总了Java中com.google.android.gms.ads.mediation.NativeMediationAdRequest.isContentAdRequested方法的典型用法代码示例。如果您正苦于以下问题:Java NativeMediationAdRequest.isContentAdRequested方法的具体用法?Java NativeMediationAdRequest.isContentAdRequested怎么用?Java NativeMediationAdRequest.isContentAdRequested使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.android.gms.ads.mediation.NativeMediationAdRequest
的用法示例。
在下文中一共展示了NativeMediationAdRequest.isContentAdRequested方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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();
}
示例2: 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();
}
示例3: 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);
}
示例4: 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();
}