banner



How To Have Ads Not Show On Apps On Android

Integrating the Google Mobile Ads SDK into an app is the first step toward displaying ads and earning revenue. Once you've integrated the SDK, you can choose an ad format (such as native or rewarded video) and follow the steps to implement it.

Before you begin

To prepare your app, complete the steps in the following sections.

App prerequisites

  • Use Android Studio 3.2 or higher
  • Make sure that your app's build file uses the following values:

    • A minSdkVersion of 16 or higher
    • A compileSdkVersion of 28 or higher

Set up your app in your AdMob account

Register your app as an AdMob app by completing the following steps:

  1. Sign in to or sign up for an AdMob account.

  2. Register your app with AdMob. This step creates an AdMob app with a unique AdMob App ID that is needed later in this guide.

Configure your app

  1. In your project-level build.gradle file, include Google's Maven repository and Maven central repository in both your buildscript and allprojects sections:

                  buildscript {     repositories {         google()         mavenCentral()     } }  allprojects {     repositories {         google()         mavenCentral()     } }                          
  2. Add the dependencies for the Google Mobile Ads SDK to your module's app-level Gradle file, normally app/build.gradle:

                  dependencies {   implementation 'com.google.android.gms:play-services-ads:20.5.0' }                          
  3. Add your AdMob app ID (identified in the AdMob UI) to your app's AndroidManifest.xml file. To do so, add a <meta-data> tag with android:name="com.google.android.gms.ads.APPLICATION_ID". You can find your app ID in the AdMob UI. For android:value, insert your own AdMob app ID, surrounded by quotation marks.

    <manifest>     <application>              <!-- Sample AdMob app ID: ca-app-pub-3940256099942544~3347511713 -->         <meta-data             android:name="com.google.android.gms.ads.APPLICATION_ID"             android:value="ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy"/>              </application> </manifest>            

    In a real app, use your actual AdMob app ID, not the one listed above. If you're just looking to experiment with the SDK in a Hello World app, you can use the sample app ID shown above.

    Note also that failure to add the <meta-data> tag as shown above results in a crash with the message:

                  The Google Mobile Ads SDK was initialized incorrectly.                          

    (Optional) Declare AD_ID permission for previous versions to work with Android S.

    If your app uses the Google Mobile Ads SDK version 20.4.0 or higher, you can skip this step since the SDK automatically declares the com.google.android.gms.AD_ID permission and is able to access the Advertising ID whenever it's available.

    For apps that use the Google Mobile Ads SDK version 20.3.0 or lower and are targeting Android S, you must add the com.google.android.gms.AD_ID permission in the AndroidManifest.xml file in order to target Android S:

    <manifest>     <application>         <meta-data             android:name="com.google.android.gms.ads.APPLICATION_ID"             android:value="ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy"/>          <-- For Android S devices & GMA SDK version 20.3.0 or lower -->                  <uses-permission android:name="com.google.android.gms.permission.AD_ID"/>                  </application> </manifest>                

    To learn more about the com.google.android.gms.AD_ID permission declaration, including how to disable it, please refer to this Play Console article.

Initialize the Google Mobile Ads SDK

Before loading ads, have your app initialize the Google Mobile Ads SDK by calling MobileAds.initialize() which initializes the SDK and calls back a completion listener once initialization is complete (or after a 30-second timeout). This needs to be done only once, ideally at app launch.

Ads may be preloaded by the Google Mobile Ads SDK or mediation partner SDKs upon calling MobileAds.initialize(). If you need to obtain consent from users in the European Economic Area (EEA), set any request-specific flags (such as tagForChildDirectedTreatment or tag_for_under_age_of_consent), or otherwise take action before loading ads, ensure you do so before initializing the Google Mobile Ads SDK.

Here's an example of how to call the initialize() method in an Activity:

Example MainActivity (excerpt)

Java

import com.google.android.gms.ads.MobileAds; import com.google.android.gms.ads.initialization.InitializationStatus; import com.google.android.gms.ads.initialization.OnInitializationCompleteListener;  public class MainActivity extends AppCompatActivity {     protected void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.activity_main);          MobileAds.initialize(this, new OnInitializationCompleteListener() {             @Override             public void onInitializationComplete(InitializationStatus initializationStatus) {             }         });     } }            

Kotlin

import com.google.android.gms.ads.MobileAds  class MainActivity : AppCompatActivity() {     override fun onCreate(savedInstanceState: Bundle?) {         super.onCreate(savedInstanceState)         setContentView(R.layout.activity_main)          MobileAds.initialize(this) {}     } }            

If you're using mediation, wait until the completion handler is called before loading ads, as this will ensure that all mediation adapters are initialized.

Select an ad format

The Google Mobile Ads SDK is now imported and you're ready to implement an ad. AdMob offers a number of different ad formats, so you can choose the one that best fits your app's user experience.

Rectangular ads that appear at the top or bottom of the device screen. Banner ads stay on screen while users are interacting with the app, and can refresh automatically after a certain period of time. If you're new to mobile advertising, they're a great place to start.

Implement banner ads

Interstitial

Full-screen ads that cover the interface of an app until closed by the user. They're best used at natural pauses in the flow of an app's execution, such as between levels of a game or just after a task is completed.

Implement interstitial ads

Native

Customizable ads that match the look and feel of your app. You decide how and where they're placed, so the layout is more consistent with your app's design.

Implement native ads

Rewarded

Ads that reward users for watching short videos and interacting with playable ads and surveys. Used for monetizing free-to-play apps.

Implement rewarded ads

Additional resources

The Google Mobile Ads repository on GitHub demonstrates how to use the different ad formats that this API offers.

How To Have Ads Not Show On Apps On Android

Source: https://developers.google.com/admob/android/quick-start

Posted by: galvanlaideard.blogspot.com

0 Response to "How To Have Ads Not Show On Apps On Android"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel