ادغام Google Mobile Ads SDK در یک برنامه اولین گام برای نمایش تبلیغات و کسب درآمد است. هنگامی که SDK را ادغام کردید، میتوانید یک قالب تبلیغاتی (مانند ویدیوی بومی یا جایزه دار) را انتخاب کنید و مراحل اجرای آن را دنبال کنید.
قبل از شروع
برای آماده سازی اپلیکیشن خود، مراحل زیر را انجام دهید.
پیش نیازهای اپلیکیشن
مطمئن شوید که فایل ساخت برنامه شما از مقادیر زیر استفاده می کند:
حداقل نسخه SDK 23 یا بالاتر
نسخه SDK 34 یا بالاتر را کامپایل کنید
برنامه خود را در حساب AdMob خود تنظیم کنید
با انجام مراحل زیر، برنامه خود را به عنوان یک برنامه AdMob ثبت کنید:
شناسه برنامه AdMob خود را، همانطور که در رابط وب AdMob مشخص شده است ، به فایل AndroidManifest.xml برنامه خود اضافه کنید. برای انجام این کار، یک تگ <meta-data> با android:name="com.google.android.gms.ads.APPLICATION_ID" اضافه کنید. میتوانید شناسه برنامه خود را در رابط وب AdMob پیدا کنید. برای android:value ، شناسه برنامه AdMob خود را که با علامت نقل قول احاطه شده است، وارد کنید.
شناسه برنامه AdMob خود را جایگزین SAMPLE_APP_ID کنید. هنگام آزمایش، از نمونه شناسه برنامه نشان داده شده در مثال قبلی استفاده کنید.
همچنین، توجه داشته باشید که عدم اضافه کردن تگ <meta-data> دقیقاً همانطور که نشان داده شده است باعث خرابی پیام می شود:
Missing application ID.
(اختیاری) مجوز AD_ID برای نسخههای قبلی برای کار با Android 13 اعلام کنید.
اگر برنامه شما از Google Mobile Ads SDK نسخه 20.4.0 یا بالاتر استفاده میکند، میتوانید این مرحله را رد کنید زیرا SDK بهطور خودکار مجوز com.google.android.gms.permission.AD_ID را اعلام میکند و میتواند هر زمان که شناسه تبلیغات در دسترس باشد به آن دسترسی پیدا کند.
برای برنامههایی که از Google Mobile Ads SDK نسخه 20.3.0 یا پایینتر استفاده میکنند و Android 13 را هدف قرار میدهند، باید مجوز com.google.android.gms.permission.AD_ID را در فایل AndroidManifest.xml برای Google Mobile Ads SDK اضافه کنید تا به شناسه تبلیغات دسترسی پیدا کنید:
برای کسب اطلاعات بیشتر در مورد اعلامیه مجوز com.google.android.gms.permission.AD_ID ، از جمله نحوه غیرفعال کردن آن، به این مقاله کنسول Play مراجعه کنید.
Google Mobile Ads SDK را راهاندازی کنید
قبل از بارگیری تبلیغات، با فراخوانی MobileAds.initialize() SDK Ads Google Mobile را مقداردهی کنید.
این روش SDK را مقداردهی اولیه میکند و یک شنونده تکمیل را پس از تکمیل مقداردهی اولیه SDK و آداپتور Google Mobile Ads یا پس از 30 ثانیه بازخوانی میکند. این کار باید فقط یک بار انجام شود، ایده آل در هنگام راه اندازی برنامه.
تبلیغات ممکن است توسط Google Mobile Ads SDK یا SDK های شریک میانجی پس از شروع اولیه بارگیری شوند. اگر نیاز به کسب رضایت از کاربران در منطقه اقتصادی اروپا (EEA) دارید، هر گونه پرچم خاص درخواست را تنظیم کنید، مانند setTagForChildDirectedTreatment() یا setTagForUnderAgeOfConsent() ، یا در غیر این صورت قبل از بارگیری تبلیغات اقدامی انجام دهید، مطمئن شوید که این کار را قبل از راه اندازی SDK تبلیغات تلفن همراه Google انجام دهید.
در اینجا مثالی از نحوه فراخوانی متد initialize() در یک رشته پس زمینه در یک Activity آورده شده است:
جاوا
newThread(()->{// Initialize the Google Mobile Ads SDK on a background thread.MobileAds.initialize(this,initializationStatus->{});}).start();
Google Mobile Ads SDK اکنون وارد شده است و شما آماده اجرای یک تبلیغ هستید. AdMob فرمتهای مختلف تبلیغاتی را ارائه میدهد، بنابراین میتوانید یکی را انتخاب کنید که به بهترین وجه با تجربه کاربری برنامهتان مطابقت دارد.
بنر
واحدهای تبلیغات بنری، تبلیغات مستطیلی را نشان میدهند که بخشی از طرحبندی برنامه را اشغال میکنند. آنها می توانند پس از مدت زمان مشخصی به طور خودکار بازخوانی شوند. این بدان معناست که کاربران یک تبلیغ جدید را در فواصل زمانی منظم مشاهده می کنند، حتی اگر در همان صفحه در برنامه شما بمانند. آنها همچنین ساده ترین قالب تبلیغاتی برای پیاده سازی هستند.
واحدهای تبلیغات بینابینی تبلیغات تمام صفحه را در برنامه شما نشان می دهند. آنها را در وقفه ها و جابجایی های طبیعی در رابط برنامه خود قرار دهید، مانند پس از اتمام سطح در یک برنامه بازی.
تبلیغات بومی تبلیغاتی هستند که در آنها میتوانید نحوه نمایش داراییهایی مانند سرفصلها و فراخوانهای اقدام را در برنامههای خود سفارشی کنید. با طراحی خود تبلیغ، می توانید یک نمایش تبلیغاتی طبیعی و بدون مزاحمت ایجاد کنید که می تواند به تجربه کاربری غنی اضافه کند.
واحدهای تبلیغاتی دارای پاداش، کاربران را قادر میسازد تا برای کسب جوایز درونبرنامهای، مانند سکه، زندگی اضافی یا امتیاز، بازی انجام دهند، نظرسنجی کنند یا ویدیو تماشا کنند. میتوانید پاداشهای مختلفی را برای واحدهای تبلیغاتی مختلف تعیین کنید و مقادیر پاداش و مواردی را که کاربر دریافت کرده است را مشخص کنید.
بینابینی پاداشدار نوع جدیدی از قالبهای تبلیغاتی با انگیزه است که به شما امکان میدهد برای تبلیغاتی که بهطور خودکار در طول انتقال طبیعی برنامه ظاهر میشوند، پاداشهایی مانند سکه یا زندگی اضافی ارائه دهید.
برخلاف آگهیهای دارای پاداش، کاربران مجبور نیستند برای مشاهده یک بینابینی پاداشدار شرکت کنند.
به جای اعلان انتخاب در تبلیغات دارای پاداش، مطالب بینابینی دارای پاداش نیاز به یک صفحه مقدماتی دارند که پاداش را اعلام می کند و به کاربران این فرصت را می دهد که در صورت تمایل از انجام این کار انصراف دهند.
تاریخ آخرین بهروزرسانی 2025-09-02 بهوقت ساعت هماهنگ جهانی.
[[["درک آسان","easyToUnderstand","thumb-up"],["مشکلم را برطرف کرد","solvedMyProblem","thumb-up"],["غیره","otherUp","thumb-up"]],[["اطلاعاتی که نیاز دارم وجود ندارد","missingTheInformationINeed","thumb-down"],["بیشازحد پیچیده/ مراحل بسیار زیاد","tooComplicatedTooManySteps","thumb-down"],["قدیمی","outOfDate","thumb-down"],["مشکل ترجمه","translationIssue","thumb-down"],["مشکل کد / نمونهها","samplesCodeIssue","thumb-down"],["غیره","otherDown","thumb-down"]],["تاریخ آخرین بهروزرسانی 2025-09-02 بهوقت ساعت هماهنگ جهانی."],[[["\u003cp\u003eIntegrating the Google Mobile Ads SDK is the initial step to display ads in your app and generate revenue, followed by choosing an ad format (like native or rewarded video) and implementing it.\u003c/p\u003e\n"],["\u003cp\u003eBefore starting, ensure your app has a minimum SDK version of 21, a compile SDK version of 33 or higher, and is registered with AdMob to obtain a unique AdMob App ID.\u003c/p\u003e\n"],["\u003cp\u003eConfigure your app by including Google's and Maven Central's repositories, adding the Google Mobile Ads SDK dependency, and inserting your AdMob App ID in your \u003ccode\u003eAndroidManifest.xml\u003c/code\u003e file.\u003c/p\u003e\n"],["\u003cp\u003eInitialize the Google Mobile Ads SDK before loading ads by calling \u003ccode\u003eMobileAds.initialize()\u003c/code\u003e once, preferably during app launch, to ensure all mediation adapters are initialized.\u003c/p\u003e\n"],["\u003cp\u003eChoose from various ad formats offered by AdMob, including banner, interstitial, native, rewarded, rewarded interstitial, and app open ads, to best suit your app's user experience.\u003c/p\u003e\n"]]],["To start displaying ads, integrate the Google Mobile Ads SDK into your app. Ensure your app's minimum SDK version is 21 or higher, and compile SDK is 34 or higher. Register your app in AdMob to get a unique App ID. Configure your app by including Google's Maven and Maven central repositories, adding SDK dependencies in the build file, and inserting your AdMob app ID into `AndroidManifest.xml`. Initialize the SDK with `MobileAds.initialize()` on app launch, preferably on a background thread. Choose an ad format (banner, interstitial, native, rewarded, rewarded interstitial, or app open) to implement.\n"],null,["Select platform: [Android](/admob/android/quick-start \"View this page for the Android platform docs.\") [iOS](/admob/ios/quick-start \"View this page for the iOS platform docs.\") [Unity](/admob/unity/quick-start \"View this page for the Unity platform docs.\") [Flutter](/admob/flutter/quick-start \"View this page for the Flutter platform docs.\")\n\n\u003cbr /\u003e\n\nIntegrating Google Mobile Ads SDK into an app is the first step toward displaying ads\nand earning revenue. Once you've integrated the SDK, you can choose an ad\nformat (such as native or rewarded video) and follow the steps to implement it.\n\nBefore you begin\n\nTo prepare your app, complete the steps in the following sections.\n\nApp prerequisites\n\n- Make sure that your app's build file uses the following values:\n\n - Minimum SDK version of `23` or higher\n - Compile SDK version of `34` or higher\n\nSet up your app in your AdMob account\n\nRegister your app as an AdMob app by completing the following steps:\n\n1. [Sign in to](//admob.google.com/home/) or [sign up\n for](//support.google.com/admob/answer/7356219) an AdMob account.\n\n2. [Register your app with AdMob](//support.google.com/admob/answer/2773509).\n This step creates an AdMob app with a unique [AdMob App\n ID](//support.google.com/admob/answer/7356431) that is needed later in this\n guide.\n\nConfigure your app\n\n1. In your Gradle settings file, include the\n [Google's Maven repository](//maven.google.com/web/index.html) and\n [Maven central repository](//search.maven.org/artifact):\n\n Kotlin \n\n ```kotlin\n pluginManagement {\n repositories {\n google()\n mavenCentral()\n gradlePluginPortal()\n }\n }\n\n dependencyResolutionManagement {\n repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)\n repositories {\n google()\n mavenCentral()\n }\n }\n\n rootProject.name = \"My Application\"\n include(\":app\")\n ```\n\n Groovy \n\n ```groovy\n pluginManagement {\n repositories {\n google()\n mavenCentral()\n gradlePluginPortal()\n }\n }\n\n dependencyResolutionManagement {\n repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)\n repositories {\n google()\n mavenCentral()\n }\n }\n\n rootProject.name = \"My Application\"\n include ':app'\n ```\n2. Add the dependencies for Google Mobile Ads SDK to your app-level build file:\n\n Kotlin \n\n ```kotlin\n dependencies {\n implementation(\"com.google.android.gms:play-services-ads:24.5.0\")\n }\n ```\n\n Groovy \n\n ```groovy\n dependencies {\n implementation 'com.google.android.gms:play-services-ads:24.5.0'\n }\n ```\n3. Click **Sync Now** . For details on syncing, see\n [Sync projects with Gradle files](https://developers.android.com/build#sync-files).\n\n4. Add your AdMob app ID, as\n [identified in the AdMob web interface](//support.google.com/admob/answer/7356431),\n to your app's `AndroidManifest.xml` file. To do so, add a `\u003cmeta-data\u003e` tag\n with `android:name=\"com.google.android.gms.ads.APPLICATION_ID\"`. You can find\n your **app ID** in the AdMob web interface. For\n `android:value`, insert your own AdMob app ID,\n surrounded by quotation marks.\n\n \u003cmanifest\u003e\n \u003capplication\u003e\n \\\u003c!-- Sample AdMob app ID: ca-app-pub-3940256099942544\\~3347511713 --\\\u003e\n \\\u003cmeta-data\n android:name=\"com.google.android.gms.ads.APPLICATION_ID\"\n android:value=\"\u003cvar class=\"readonly\" translate=\"no\"\u003eSAMPLE_APP_ID\u003c/var\u003e\"/\\\u003e\n \u003c/application\u003e\n \u003c/manifest\u003e\n\n Replace \u003cvar class=\"readonly\" translate=\"no\"\u003eSAMPLE_APP_ID\u003c/var\u003e with your AdMob app ID. While\n testing, use the sample app ID shown in the previous example.\n\n Also, note that failure to add the `\u003cmeta-data\u003e` tag exactly as shown results\n in a crash with the message: \n\n Missing application ID.\n\n (Optional) Declare\n `AD_ID` permission for previous versions to work with Android\n 13.\n\n If your app uses Google Mobile Ads SDK version **20.4.0** or\n higher, you can skip this step since the SDK automatically declares the\n `com.google.android.gms.permission.AD_ID` permission and is able\n to access the Advertising ID whenever it's available.\n\n For apps that use Google Mobile Ads SDK version **20.3.0** or\n lower and are targeting Android 13, you must add the\n `com.google.android.gms.permission.AD_ID` permission in the\n `AndroidManifest.xml` file for Google Mobile Ads SDK to access the\n Advertising ID: \n\n ```xml\n \u003cmanifest\u003e\n \u003capplication\u003e\n \u003cmeta-data\n android:name=\"com.google.android.gms.ads.APPLICATION_ID\"\n android:value=\"ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy\"/\u003e\n\n \u003c!-- For apps targeting Android 13 or higher & GMA SDK version 20.3.0 or lower --\u003e\n \u003cuses-permission android:name=\"com.google.android.gms.permission.AD_ID\"/\u003e\n\n \u003c/application\u003e\n \u003c/manifest\u003e\n ```\n\n To learn more about the\n `com.google.android.gms.permission.AD_ID` permission declaration,\n including how to disable it, refer to this [Play\n Console article](//support.google.com/googleplay/android-developer/answer/6048248).\n\nInitialize the Google Mobile Ads SDK Before loading ads, initialize Google Mobile Ads SDK by calling [`MobileAds.initialize()`](/admob/android/reference/com/google/android/gms/ads/MobileAds#initialize(android.content.Context,%20com.google.android.gms.ads.initialization.OnInitializationCompleteListener)).\n\nThis method initializes the SDK and calls a completion listener once both\nGoogle Mobile Ads SDK and adapter initializations have completed, or after a\n30-second timeout. This needs to be done only once, ideally at app launch.\n| **Note:** If you're using AdMob Mediation, wait until the completion handler is called before loading ads. This ensures that all mediation adapters are initialized.\n\n**Ads may be preloaded by Google Mobile Ads SDK or mediation partner SDKs\nupon initialization.** If you need to obtain consent from users in the European\nEconomic Area (EEA), set any request-specific flags, such as\n\n[`setTagForChildDirectedTreatment()`](/admob/android/reference/com/google/android/gms/ads/RequestConfiguration.Builder#setTagForChildDirectedTreatment(int))\nor\n[`setTagForUnderAgeOfConsent()`](/admob/android/reference/com/google/android/gms/ads/RequestConfiguration.Builder#setTagForUnderAgeOfConsent(int)),\n\nor\notherwise take action before loading ads, ensure you do so before initializing\nGoogle Mobile Ads SDK.\n\nHere's an example of how to call the `initialize()` method on a background\nthread within an Activity: \n\nJava \n\n new Thread(\n () -\u003e {\n // Initialize the Google Mobile Ads SDK on a background thread.\n MobileAds.initialize(this, initializationStatus -\u003e {});\n })\n .start(); \n https://github.com/googleads/googleads-mobile-android-examples/blob/ccc290a583d7f552bdcf81ea76adc05beaa43f0b/java/admob/BannerExample/app/src/main/java/com/google/android/gms/example/bannerexample/MyActivity.java#L195-L204\n\nKotlin \n\n CoroutineScope(Dispatchers.IO).launch {\n // Initialize the Google Mobile Ads SDK on a background thread.\n MobileAds.initialize(this@MainActivity) {}\n } \n https://github.com/googleads/googleads-mobile-android-examples/blob/ccc290a583d7f552bdcf81ea76adc05beaa43f0b/kotlin/admob/BannerExample/app/src/main/java/com/google/android/gms/example/bannerexample/MainActivity.kt#L167-L176\n\nSelect an ad format\n\nGoogle Mobile Ads SDK is now imported and you're ready to implement an ad.\nAdMob offers a number of different ad formats, so\nyou can choose the one that best fits your app's user experience.\n\nBanner\n\nBanner ad units display rectangular ads that occupy a portion of an app's\nlayout. They can refresh automatically after a set period of time. This means\nusers view a new ad at regular intervals, even if they stay on the same\nscreen in your app. They're also the simplest ad format to implement. \n\n[Implement banner ads](/admob/android/banner)\n\nInterstitial\n\nInterstitial ad units show full-page ads in your app. Place them at natural\nbreaks and transitions in your app's interface, such as after level completion\nin a gaming app. \n\n[Implement interstitial ads](/admob/android/interstitial)\n\nNative\n\nNative ads are ads where you can customize the way assets such as headlines and\ncalls to action are presented in your apps. By styling the ad yourself, you can\ncreate a natural, unobtrusive ad presentations that can add to a rich user\nexperience. \n\n[Implement native ads](/admob/android/native)\n\nRewarded\n\nRewarded ad units enable users to play games, take surveys, or watch videos to\nearn in-app rewards, such as coins, extra lives, or points. You can set\ndifferent rewards for different ad units, and specify the reward values and\nitems the user received. \n\n[Implement rewarded ads](/admob/android/rewarded)\n\nRewarded interstitial\n\nRewarded interstitial is a new type of incentivized ad format that lets you\noffer rewards, such as coins or extra lives, for ads that appear automatically\nduring natural app transitions.\n\nUnlike rewarded ads, users aren't required to opt in to view a rewarded\ninterstitial.\n\nInstead of the opt-in prompt in rewarded ads, rewarded interstitials require an\nintro screen that announces the reward and gives users a chance to opt out if\nthey want to do so. \n\n[Implement rewarded interstitial ads](/admob/android/rewarded-interstitial)\n\nApp open\n\nApp open is an ad format that appears when users open or switch back to your\napp. The ad overlays the loading screen. \n\n[Implement app open ads](/admob/android/app-open)\n\nAdditional resources\n\nThe [Google Mobile Ads repository](//github.com/googleads/googleads-mobile-android-examples) on GitHub demonstrates\nhow to use the different ad formats that this API offers."]]