ArminKh1993
Active Member
Hi there
Ok,I think the time has come to release my library over the new version of Google Mobile Ads SDK.
This library is fully compatible with the new version(20.0.0) of GoogleMobileAds SDK.
Have a look at it. (https://developers.google.com/admob/android/migration)
All changes in the link above have been applied in this version of my library.
Supported Ad Formats:
- Banner (With Adaptive Banner) | https://developers.google.com/admob/android/banner
- Interstitial | https://developers.google.com/admob/android/interstitial-fullscreen
- Rewarded | https://developers.google.com/admob/android/rewarded-fullscreen
- Rewarded Interstitial | https://developers.google.com/admob/android/rewarded-interstitial
- App Open | https://developers.google.com/admob/android/app-open-ads
- Native | https://developers.google.com/admob/android/native/start
Note:
Before doing anything, choose whether you want to use Admob with Firebase? Or Standalone?
You can read the difference between using them in this link.(Use more features of Google Analytics and Firebase with AdMob apps)
How to implement Admob(With Firebase):
- First have a look at document: https://firebase.google.com/docs/admob/android/quick-start
- Then you need to follow the Firebase integration tutorial( Make sure to include the Ads manifest snippet): https://www.b4x.com/android/forum/threads/integrating-firebase-services.67692/
- Add this code to your "Project Attributes" of Main activity:
B4X:
#AdditionalJar: com.google.firebase:firebase-ads
How to implement Admob(Without Firebase):
- First have a look at document: https://developers.google.com/admob/android/quick-start
- Add this codes to your manifest:
B4X:
AddApplicationText(
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="@android:style/Theme.Translucent" />
<activity android:name="com.google.android.gms.ads.purchase.InAppPurchaseActivity"
android:theme="@style/Theme.IAPTheme"/>
<provider
android:name="com.google.android.gms.ads.MobileAdsInitProvider"
android:authorities="${applicationId}.mobileadsinitprovider"
android:exported="false"
android:initOrder="100" />
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="$ADMOB_APP_ID$"/>
)
Note: Instead of code above you can use this one from Firebase integration tutorial too:
B4X:
CreateResourceFromFile(Macro, FirebaseAdMob.FirebaseAds)
- Then add your AdmobAppId and GooglePlayService macro to your manifest:
B4X:
AddReplacement($ADMOB_APP_ID$, ca-app-pub-3940256099942544~3347511713)
CreateResourceFromFile(Macro, FirebaseAnalytics.GooglePlayBase)
- Add this code to your "Project Attributes" of Main activity:
B4X:
#AdditionalJar: com.google.android.gms:play-services-ads
Ok, Now everything is ready to display your ads.But you need to know a few important points.
- This library is compatible with b4a v10.7 or higher.
- This library is compatible with Admob version 19.7 or higher, So if you see any errors, please update your SDK first. To install it please start SDK Manager and in search field type: com.google.android.gms: play-services-ads and com.google.firebase:firebase-ads and install it.
- You should Initializes the Google Mobile Ads SDK. The SDK will configure itself. Call this method as early as possible, and only once per application launch(Maybe in Starter_Create).
B4X:
Dim MobileAds As MobileAds
MobileAds.Initialize
- By default, the Google Mobile Ads SDK initializes app measurement and begins sending user-level event data to Google immediately when the app starts. This initialization behavior ensures you can enable AdMob user metrics without making additional code changes. However, if your app requires user consent before these events can be sent, you can delay app measurement until you explicitly initialize the Mobile Ads SDK or load an ad. To delay app measurement, add the following <meta-data> tag in your Manifest. Delay app measurement until MobileAds.initialize() is called.
B4X:
AddApplicationText(
<meta-data
android:name="com.google.android.gms.ads.DELAY_APP_MEASUREMENT_INIT"
android:value="true"/>
)
- For video ads to show successfully in your banner ad views or in native video ads, hardware acceleration must be enabled.(Add to manifest)
B4X:
SetApplicationAttribute(android:hardwareAccelerated, "true")
- You can also use lite version of google mobile ads sdk. just replace your code in "Project Attributes" of Main activity with lite versions. Like any Android library, the Google Play services SDK increases the size of apps that include it. The Google Mobile Ads Lite SDK is a lightweight version of the Google Mobile Ads SDK built to reduce that impact. It is a fraction of the size of the regular SDK.
Alongside reduced size, using the Lite SDK decreases the total number of methods referenced in an app. This is especially useful when deploying to older versions of Android, where developers can run into the 64K reference limit. (https://developers.google.com/admob/android/lite-sdk)
#AdditionalJar: com.google.firebase:firebase-ads
==> #AdditionalJar: com.google.firebase:firebase-ads-lite
#AdditionalJar: com.google.android.gms:play-services-ads
==> #AdditionalJar: com.google.android.gms:play-services-ads-lite
Limitations of the Lite SDK
The Lite SDK should only be used in apps distributed through the Google Play store.
Attachments
Last edited: