How to Secure Admob Adunit Ids Using Firebase | Android Studio Firebase Tutorials

How to Secure Admob Adunit Ids Using Firebase  | Android Studio Firebase Tutorials:

Friends  I will tell you how to control admob adunit id From Firebase and Secure Your admob Adunit Id's you can simply follow these steps to secure your admob adunit  ids using firebase.
for this method you can change admob adunit id's from firebase server. 

  1.  Create Android Studio Empty Prjoect
  2.  Create Button For Show Ads
  3.  Create Firebase Project
  4.  Dependencies 
  5.  Firebase Java Code For Admob Ads
  6.  Interstitial Ads Java Code
  7.  Run your App and Check it

1. Create Android Studio Project For Firebase Admob Ads

First You Can Create Android Empty Project Follow Steps Below
4. Now Can Create a Simple Android Studio Empty Project Easily. Now Can Create A button for Showing  Admob Ads From Firebase Server.

How to Create Button in Android Studio For Showing Admob Ads using Firebase:

First We goto Xml File of Our Project and Simply Copy Below Code and Replace it into your activity_main.xml file..

<?xml version="1.0" encoding="utf-8"?>

        android:text="Show Ad"
        android:layout_height="wrap_content" />


Now Goto MainActivity.Java and Past this Code Under AppCompact Actvity .
    Button btn;
Now Goto MainActivity.Java and Past this code Under Oncreate mehod
btn = findViewById(;
 btn.setOnClickListener(new View.OnClickListener() {
 @Override public void onClick(View v) { 
 AdRequest adRequest = new AdRequest.Builder().build();
 if (mInterstitialAd.isLoaded()) {; 
{ Log.d("TAG", "The interstitial wasn't loaded yet.");

  1.  Create Firebase Project for Admob Ads
  • Open the Firebase Website, Goto Console and Ad a Project. 
  • gave project Name , tik on Accept and then click create project
  • Now Click Android Icon
  • now Register App in Firebase Project for Control Admob Adunit id's
  • after Register the app Goto Download and Config Simply Download googleservice.json file and and past it into your project apps folder. Watch Video for Any Problem, and Copy dependcies and past it into the project into grademodule.  You can find dependcies in depedencies heading of this article and watch video for complete setup.

4.dependencies for Firebase Admob Ads Project

implementation ''
        implementation ''
    implementation ''
    implementation 'com.firebase:firebase-client-android:2.5.1'
apply plugin: ''
classpath ''

5.Java Code For Firebase Implementations:

        Firebase myFirebase = new Firebase("");
        myFirebase.addValueEventListener(new ValueEventListener() {
            public void onDataChange(DataSnapshot dataSnapshot) {
                MyAdUnitId = dataSnapshot.getValue(String.class);



            public void onCancelled(FirebaseError firebaseError) {


6.Java Code For Admob Interstitial Ads:

mInterstitialAd = new InterstitialAd(this);

                mInterstitialAd.loadAd(new AdRequest.Builder().build());

AdRequest adRequest = new AdRequest.Builder().build();

                if (mInterstitialAd.isLoaded()) {
                } else {
                    Log.d("TAG", "The interstitial wasn't loaded yet.");

now run the app and try to check if you have any problem please comment me and i will solve your problem..

Next Post »