Android Question Question about admob with Firebase

azad222

Member
I used the following code.
codeadmob:
Sub Process_Globals

End Sub

Sub Globals
   Private BannerAd As AdView
   Private IAd As InterstitialAd
End Sub

Sub Activity_Create(FirstTime As Boolean)
   BannerAd.Initialize2("BannerAd", "ca-app-pub-3940256099942544/6300978111", BannerAd.SIZE_SMART_BANNER)
   Dim height As Int
   If GetDeviceLayoutValues.ApproximateScreenSize < 6 Then
    'phones
    If 100%x > 100%y Then height = 32dip Else height = 50dip
   Else
    'tablets
    height = 90dip
   End If
   Activity.AddView(BannerAd, 0dip, 100%y - height, 100%x, height)
   BannerAd.LoadAd
   IAd.Initialize("iad", "ca-app-pub-3940256099942544/1033173712")
   IAd.LoadAd
End Sub

Sub Activity_Click
   If IAd.Ready Then IAd.Show
End Sub

Sub IAD_AdClosed
   IAd.LoadAd 'prepare a new ad
End Sub

Google's test code works. But my codes are not displayed.
Do I need to add this code while working?

https://firebase.google.com/docs/admob/android/quick-start

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

azad222

Member
I did the following step by step:
step1: First I went to the link below:
https://console.firebase.google.com/
And I made an Android project. I was given a json code.
Download google-services.json and put it in the projects folder (folder of the b4a file).

step2: Add the manifest snippets to the manifest editor based on the services that you need.

add manifest:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="29"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
CreateResourceFromFile(Macro, Themes.LightTheme)
'End of default text.


'AdMob
AddApplicationText(
<meta-data android:name="com.google.android.gms.version"
  android:value="[USER=21225]@Integer[/USER]/google_play_services_version"/>
<activity android:name="com.google.android.gms.ads.AdActivity"
  android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
)

'AdMob
AddApplicationText(
<meta-data
            android:name="com.google.android.gms.ads.ca-app-pub-7920067095036570~8669178654"
            android:value="ca-app-pub-7920067095036570~8669178654"/>
)

'power by milad biroonvand

[B]step3:  Follow the instructions of the specific libraries.  (check use firebaseadmob v1.6)[/B]
[CODE lang="b4x" title="b4acode"]Sub Process_Globals

End Sub

Sub Globals
   Private BannerAd As AdView
   Private IAd As InterstitialAd
End Sub

Sub Activity_Create(FirstTime As Boolean)
   BannerAd.Initialize2("BannerAd", "ca-app-pub-3940256099942544/6300978111", BannerAd.SIZE_SMART_BANNER)
   Dim height As Int
   If GetDeviceLayoutValues.ApproximateScreenSize < 6 Then
    'phones
    If 100%x > 100%y Then height = 32dip Else height = 50dip
   Else
    'tablets
    height = 90dip
   End If
   Activity.AddView(BannerAd, 0dip, 100%y - height, 100%x, height)
   BannerAd.LoadAd
   IAd.Initialize("iad", "ca-app-pub-3940256099942544/1033173712")
   IAd.LoadAd
End Sub

Sub Activity_Click
   If IAd.Ready Then IAd.Show
End Sub

Sub IAD_AdClosed
   IAd.LoadAd 'prepare a new ad
End Sub

step4: I compiled the project
But the following error occurred: error Error Code 0
Google has announced the following errors:
source:

Error Code 0 : ERROR_CODE_INTERNAL_ERROR

This indicates that something happened internally; for instance, an invalid response was received from the ad server.
Newly created Ad Units can take upto 2 hours to become active (SpinUp Time). Any Ad requests from newly created Ad Units would also receive Error Code 0 in response to Ad requests until they are ready to serve live ads.
What to do? Test Ads!!
  • Error Code 1 : ERROR_CODE_INVALID_REQUEST
The ad request was invalid; for instance, the ad unit ID was incorrect.
This commonly suggests that the Ad Request implementation is not as per the SDK’s requirements - Resources like the sample codes and sample apps provided in the developer documentation can help in implementing the functions correctly.
That's all I've done

  • Error Code 2 : ERROR_CODE_NETWORK_ERROR

The ad request was unsuccessful due to network connectivity.
This could be due to a user’s phone switching networks or network disturbances distorting the communication between the app and the Ad Server. Some Telecom providers may also limit specific traffic due to policy, which can also lead to such an error.


  • Error Code 3 : ERROR_CODE_NO_FILL
Description (Dev Docs Link) : The ad request was successful, but no ad was returned due to lack of ad inventory.
Why is it Happening : Advertisers can target specific regions, platforms and user profiles based on business relevance, which can sometimes result in lower availability of Ads for a particular region or user profile. Error code suggests that the implementation is correct, and that the Ad Request was not filled because of lack of availability of a suitable Ad at that particular instant of time when an Ad Request was sent from the app.
Policy related restrictions on certain Apps or Ad Units will also lead to Error Code 3 being returned in response to Ad Requests.
What Can The Pub Do About it :
 

Attachments

  • json.jpg
    json.jpg
    14 KB · Views: 135
  • khata2.jpg
    khata2.jpg
    26.7 KB · Views: 149
Upvote 0

asales

Expert
Licensed User
Longtime User
Check this example that have all code to work with Admob:
 
Upvote 0

asales

Expert
Licensed User
Longtime User
Yes and the best one, I have found.
Many thanks to @asales 👍

Regards,

Anand
Thanks!
The example was updated:
 
Upvote 0
Top