"الإعلانات البينية" هي إعلانات بملء الشاشة تغطي واجهة التطبيق. يمكنك عرض هذه الإعلانات في نقاط انتقال طبيعية في تطبيقك، مثل بين الأنشطة أو أثناء فترات التوقف المؤقت في مستويات اللعبة.
عندما يعرض تطبيقك "إعلانًا بينيًا"، يمكن للمستخدمين إما النقر على الإعلان والمتابعة، أو إغلاق الإعلان والعودة إلى التطبيق.
يشرح هذا الدليل كيفية دمج "الإعلانات البينية" في تطبيق Android.
قبل البدء
قبل المتابعة، عليك تنفيذ ما يلي:
- إعداد GMA Next-Gen SDK
- استخدِم معرّف الوحدة الإعلانية البينية الاختبارية
ca-app-pub-3940256099942544/1033173712.- عند إنشاء تطبيقك واختباره، تأكَّد من استخدام الإعلانات الاختبارية بدلاً من الإعلانات المباشرة والنهائية. إذا لم تستخدم معرّف الوحدة الإعلانية الاختبارية، يمكن أن تعلّق Google حسابك.
- قبل نشر تطبيقك، استبدِل هذا المعرّف بمعرّف الوحدة الإعلانية.
- لمعرفة تفاصيل عن الإعلانات الاختبارية في GMA Next-Gen SDK، يُرجى الاطّلاع على مقالة تفعيل الإعلانات الاختبارية.
تحميل إعلان
يحمّل المثال التالي إعلانًا واحدًا:
Kotlin
// Load ads after you initialize MobileAds. InterstitialAd.load( AdRequest.Builder(adUnitId).build(), object : AdLoadCallback<InterstitialAd> { override fun onAdLoaded(ad: InterstitialAd) { // Interstitial ad loaded. interstitialAd = ad } override fun onAdFailedToLoad(adError: LoadAdError) { // Interstitial ad failed to load. Log.e(TAG, "Interstitial ad failed to load: ${adError.message}") interstitialAd = null } }, )
جافا
// Load ads after you initialize MobileAds. InterstitialAd.load( new AdRequest.Builder(adUnitId).build(), new AdLoadCallback<InterstitialAd>() { @Override public void onAdLoaded(@NonNull InterstitialAd ad) { // Interstitial ad loaded. interstitialAd = ad; } @Override public void onAdFailedToLoad(@NonNull LoadAdError adError) { // Interstitial ad failed to load. Log.e(TAG, "Interstitial ad failed to load: " + adError.getMessage()); interstitialAd = null; } });
عند الاختبار، استخدِم معرّف الوحدة الإعلانية الاختبارية:
ca-app-pub-3940256099942544/1033173712.
عرض الإعلان
لعرض "إعلان بيني"، استخدِم طريقةshow.
يعرض المثال التالي الإعلان:
Kotlin
private fun showAd(interstitialAd: InterstitialAd, activity: Activity) { // Show the ad. interstitialAd.show(activity) }
جافا
private void showAd(InterstitialAd interstitialAd, Activity activity) { // Show the ad. interstitialAd.show(activity); }
الاستماع إلى أحداث الإعلانات
قبل عرض الإعلان، استمِع إلى أحداث مراحل نشاط الإعلان. يسجّل المثال التالي عمليات الاستدعاء لأحداث الإعلانات:
Kotlin
// Listen for ad events. val ad = interstitialAd if (ad == null) { Log.e(TAG, "Interstitial ad is not ready yet.") return } ad.adEventCallback = object : InterstitialAdEventCallback { override fun onAdShowedFullScreenContent() { // Interstitial ad did show. } override fun onAdDismissedFullScreenContent() { // Interstitial ad did dismiss. interstitialAd = null } override fun onAdFailedToShowFullScreenContent( fullScreenContentError: FullScreenContentError ) { // Interstitial ad failed to show. Log.e(TAG, "Interstitial ad failed to show: ${fullScreenContentError.message}") } override fun onAdImpression() { // Interstitial ad did record an impression. } override fun onAdClicked() { // Interstitial ad did record a click. } }
جافا
// Listen for ad events. if (interstitialAd == null) { Log.e(TAG, "Interstitial ad is not ready yet."); return; } interstitialAd.setAdEventCallback( new InterstitialAdEventCallback() { @Override public void onAdShowedFullScreenContent() { // Interstitial ad did show. } @Override public void onAdDismissedFullScreenContent() { // Interstitial ad did dismiss. interstitialAd = null; } @Override public void onAdFailedToShowFullScreenContent( @NonNull FullScreenContentError fullScreenContentError) { // Interstitial ad failed to show. Log.e(TAG, "Interstitial ad failed to show: " + fullScreenContentError.getMessage()); } @Override public void onAdImpression() { // Interstitial ad did record an impression. } @Override public void onAdClicked() { // Interstitial ad did record a click. } });