Как добавить промежуточную рекламу Facebook в пользовательский диалог? - PullRequest
0 голосов
/ 18 мая 2019

В моем приложении в моей основной деятельности при нажатии на спину я хочу показать диалог с рекламными вставками в фейсбуке.

Я создал собственный класс диалога, чтобы показать мой диалог, хочет ли пользователь выйти или нет на спине.нажмите кнопку прослушивания, пока объявление показывается пользователю в диалоговом окне.

Для этого настраиваемого диалогового окна я хочу, чтобы промежуточное объявление Facebook отображалось, но не получало результат, только диалоговое окно с кнопками отображается без загруженного объявления?

Как загрузить рекламные вставки Facebook в диалоге?

Это макет диалога

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/facebook_interestial_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center_horizontal"
    android:orientation="vertical"
    android:paddingTop="4dp"
    android:paddingBottom="4dp">
    <LinearLayout
        android:id="@+id/facebook_interestial_ad"
        android:layout_width="match_parent"
        android:layout_height="240dp"
        android:orientation="vertical">

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:weightSum="3.2">
        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_marginLeft="12dp"
            android:layout_weight="1.8"
            android:gravity="center"
            android:orientation="vertical">
            <TextView
                android:id="@+id/textView9"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Are you sure to exit app ?"
                android:textSize="14sp" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="0.7"
            android:orientation="vertical">

            <Button
                android:id="@+id/yes_exit_btn"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="YES" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="0.7"
            android:orientation="vertical">

            <Button
                android:id="@+id/no_exit_btn"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginRight="1dp"
                android:text="NO" />
        </LinearLayout>

    </LinearLayout>

</LinearLayout>

Это класс View Dialog

    import com.facebook.ads.AbstractAdListener;
import com.facebook.ads.Ad;

public class ViewDialog {

    com.facebook.ads.InterstitialAd interstitial;
    Ad adfacebook;
        public void showDialog(Activity activity) {
            Context c1= activity.getBaseContext();
            final Dialog dialog = new Dialog(activity);
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setCancelable(false);
            dialog.setContentView(R.layout.fbdialogexit);


            LinearLayout adlayout = (LinearLayout)dialog.findViewById(R.id.facebook_interestial_ad);



            interstitial = new com.facebook.ads.InterstitialAd(c1, "your id");
        interstitial.setAdListener(new AbstractAdListener() {
            public void onAdLoaded(Ad ad) {
                adfacebook = ad;


            }
        });
        interstitial.loadAd();

            Button dialogExitCancelButton = (Button) dialog.findViewById(R.id.no_exit_btn);
            dialogExitCancelButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    dialog.dismiss();
                }
            });


            Button dialogExitButton = (Button) dialog.findViewById(R.id.yes_exit_btn);
            dialogExitButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                   System.exit(0);
                }
            });

            dialog.show();

        }


}

Вызов в основной деятельностиназад нажмите кнопку

  @Override
public void onBackPressed() { ViewDialog alert = new ViewDialog();
    alert.showDialog(StartActivity.this);

}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...