Interstitial ads with time of interval in Android Studio

[rtcl_listings]

Interstitial ads with time of interval in Android Studio

Hello guys today  i am going to tell you how can show admob Interstitial ads with time of interval.

What you need to do before :

Prerequisites

  • Use Android Studio 3.2 or later
  • minSdkVersion 14 or later
  • compileSdkVersion 28 or later

Example project-level build.gradle (excerpt)

allprojects {
    repositories {
        google()
        jcenter()
    }
}

Add the google() directive above if it’s not already present.

Next, open the app-level build.gradle file for your app, and look for a “dependencies” section.

Example app-level build.gradle (excerpt)

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'com.google.android.gms:play-services-ads:18.3.0'
}

Add the lines in bold above, which instruct Gradle to pull in the latest version of the Mobile Ads SDK and additional related dependencies. Once that’s done, save the file and perform a Gradle sync.

Update your AndroidManifest.xml

Add your AdMob App ID to your app’s AndroidManifest.xml file by adding a <meta-data> tag with name com.google.android.gms.ads.APPLICATION_ID, as shown below.

You can find your App ID in the AdMob UI. For android:value insert your own AdMob App ID in quotes, as shown below.

<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>

Initialize Mobile Ads SDK

Before loading ads, have your app initialize the 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.

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

Example MainActivity (excerpt)

package ...
import ...
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) {
}
});
}
}

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.

Watch Video Tutorial

Click on Below button and complete task showed in pop up to Download the Script file