Integrating Admob[Part 2] | Initial Setup | Admob monetization for Android Apps | Admob tutorial

Опубликовано: 07 Февраль 2025
на канале: Shaheer Shukur
996
19

#google #admob #android
Admob guide app: https://play.google.com/store/apps/de...
Initial Setup [Part 2]
Learn how to earn money (monetize) from your android applications using google admob.
This video explains the initial setup required for the android application project for the admob to work correctly.

Source code of application: https://github.com/shaheershukur/Admo...

Closed Captioning:
In this video, let’s do the initial setup required in our application, for proper working of admob.
There are 4 tasks to be done.
Task 1:
We need to make sure our code is using androidx artifacts.
Else we need to migrate our application code to androidx.
In latest android studio, androidx artifacts can be selected during app creation.
To confirm it, open the Module level 'build.gradle' file.
If you can find the keyword 'androidx' anywhere in the dependencies section, your app supports androidx artifacts.
If not, you must migrate the application to androidx.
To do so, click on 'Refactor' menu option.
Select 'Migrate to AndroidX'.
On clicking the 'Migrate' button, the whole project will be rebuild based on androidx.

Task 2:
Now, open the App level 'build.gradle' file.
Under the 'allprojects' section, make sure the 'google()' repository is present.
If not, add it manually.
Under the Module level 'build.gradle' file, we must add admob dependency.
For that, add this 'implementation' statement under the 'dependencies' section.
Since we made changes to the 'build.gradle' file, we must click on the 'Sync Now' option.
Wait for thte build to be completed.

Task 3:
We must update the 'AndroidManifest.xml' file.
Under the 'application' tag, we must add the 'meta-data' tag.
Type the 'name' attribute exactly like this.
The 'value' attribute should be your admob App ID.
We can get the App ID from our admob account.
Here is an example.
Open Admob website.
From the 'Apps' section, click on the 'ADD APP' button.
Enter the app information and click on 'ADD'.
From here, we can copy the App ID generated for our application.
Click on the 'Copy' icon.
Now we can paste our App ID here in the 'AndroidManifest.xml' file.
Note that, we can always use the this App ID during development and testing.

Task 4:
When the user opens the application, admob must be initialized and displayed to the user.
For that, open the activity's java file.
Inside the 'onCreate' callback, call the 'initialize()' function of 'MobileAds' class.
We can pass 'this' as the only parameter to the function.
This will initialize the admob ads when the application is opened.
If in case we need to do some task after the admob is initialized,
We must also pass the 'OnInitializationCompleteListener' as the parameter.
Inside its 'OnInitializationComplete()' method, we can perform the tasks.
Anyways this is optional.

All we have to do now is to decide which ad needs to be shown in the app.
In the coming videos, let's see how to implement each ad type in our example application.