Admob родной заблаговременной реализации - PullRequest
0 голосов
/ 14 декабря 2018

Здравствуйте, я пытаюсь внедрить нативную рекламу AdMob от ref https://developers.google.com/admob/android/native/advanced, но она не работает и не может правильно понять, пожалуйста, наведите меня, или, если есть какой-то подходящий пример, поделитесь со мной, и мой код ниже:

native_advance.xml

<?xml version="1.0" encoding="utf-8"?>
<com.google.android.gms.ads.formats.UnifiedNativeAdView 
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="270dp"
    android:orientation="vertical">

    <TextView
        android:layout_width="15dp"
        android:layout_height="15dp"
        android:text="Ad"
        android:textSize="16sp" />

    <com.google.android.gms.ads.formats.MediaView
        android:id="@+id/appinstall_media"
        android:layout_width="match_parent"
        android:layout_height="170dp" />

    <TextView
        android:id="@+id/appinstall_headline"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:layout_margin="4dp"
        android:textSize="16sp" />

    <Button
        android:id="@+id/appinstall_call_to_action"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
</LinearLayout>

</com.google.android.gms.ads.formats.UnifiedNativeAdView>

кадр в основной деятельности:

<FrameLayout
android:id="@+id/native_frame"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</FrameLayout>

и в основной деятельности

private void loadNativeAds() {
    if (getApplicationContext() != null) {


        AdLoader.Builder builder = new AdLoader.Builder(this, "my_admob_id")
                .forUnifiedNativeAd(new UnifiedNativeAd.OnUnifiedNativeAdLoadedListener() {
                    @Override
                    public void onUnifiedNativeAdLoaded(UnifiedNativeAd unifiedNativeAd) {
                        // Assumes you have a placeholder FrameLayout in your View layout
                        // (with id fl_adplaceholder) where the ad is to be placed.
                        FrameLayout frameLayout =
                                findViewById(R.id.native_frame);
                        // Assumes that your ad layout is in a file call ad_unified.xml
                        // in the res/layout folder
                        UnifiedNativeAdView adView = (UnifiedNativeAdView) getLayoutInflater()
                                .inflate(R.layout.native_advance, null);
                        // This method sets the text, images and the native ad, etc into the ad
                        // view.
                        pupulateNativeAd(unifiedNativeAd, adView);
                        frameLayout.removeAllViews();
                        frameLayout.addView(adView);
                    }
                });
    }

}

1 Ответ

0 голосов
/ 10 апреля 2019

Это еще не все.Вы должны определить pupulateNativeAd(UnifiedNativeAd unifiedNativeAd,UnifiedNativeAdView adView) function.

Вот очень простое определение:

private void pupulateNativeAd(UnifiedNativeAd unifiedNativeAd, UnifiedNativeAdView adView) {
        TextView adTitle = adView.findViewById(R.id.id_native_ad_title);
        TextView adBody = adView.findViewById(R.id.id_native_ad_title);

        adTitle.setText(unifiedNativeAd.getHeadline());
        adBody.setText(unifiedNativeAd.getBody());
    }

Также смотрите эту ссылку для большей картины.

...