الإعلانات البينية هي إعلانات بملء الشاشة تغطي واجهة التطبيق. يتم عرض هذه الإعلانات في نقاط انتقال طبيعية في تطبيقك، مثل بين الأنشطة أو أثناء فترات التوقف المؤقت في مستويات اللعبة. عندما يعرض تطبيق إعلانًا بينيًا، يمكن للمستخدمين النقر على الإعلان والمتابعة أو إغلاق الإعلان والرجوع إلى التطبيق. اطّلِع على إحدى دراسات الحالة.
يوضّح هذا الدليل كيفية دمج الإعلانات البينية في تطبيق Android.
المتطلبات الأساسية
اختبار الإعلانات دائمًا باستخدام الإعلانات الاختبارية
عند إنشاء تطبيقاتك واختبارها، احرص على استخدام إعلانات اختبارية بدلاً من الإعلانات المباشرة الخاصة بالمنتج. إذا لم تستخدِم الإعلانات الاختبارية، يمكن أن تعلّق Google حسابك.
أسهل طريقة لتحميل الإعلانات الاختبارية هي استخدام رقم تعريف وحدة إعلانية اختبارية مخصّصة للإعلانات البينية على Android:
ca-app-pub-3940256099942544/1033173712
تم ضبط رقم تعريف الوحدة الإعلانية هذا خصيصًا لعرض إعلانات اختبارية لكل طلب. يمكنك استخدامها في تطبيقاتك أثناء الترميز والاختبار وتصحيح الأخطاء. احرِص على استبداله برقم تعريف وحدتك الإعلانية قبل نشر تطبيقك.
للحصول على تفاصيل حول 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. } });