Android Question FirebaseAdMob

dibesw

Active Member
Licensed User
Longtime User
In this code
B4X:
Sub LoadAd
    BannerAd.Initialize2("BannerAd", "ca-app-pub-9301XXXXXXXX5507~3463805004", 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
End Sub

which is the ID that need insert into AD UNIT ID?

A or B
and if A, must to be insert char "~" o "/"?

codea.jpg


codeb.jpg



Thanks
 
Last edited:

dibesw

Active Member
Licensed User
Longtime User
Ok ASALES, SOREX
B4X:
Sub BannerAd_FailedToReceiveAd (ErrorCode As String)
    ToastMessageShow("failed: " & ErrorCode,False)
End Sub

I take ErrorCode=3 and the banner is not issued

1) My application in FireBase is connected to AdMob
2) The ultimate google-services.json is in appdir
3) account payments is OK (in AD unit)
4) B4A 9.30
5) My app run to android 8.0
6) My account is ready (email from admob)
7) Manifest is:
B4X:
'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: http://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="28"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
'End of default text.
AddApplicationText(<activity android:name="anywheresoftware.b4a.objects.preferenceactivity"/>)
AddManifestText(<uses-feature android:name="android.hardware.location.gps"/>)
AddApplicationText(<meta-data
    android:name="com.google.android.gms.version"
    android:value="@integer/google_play_services_version" />)
AddPermission(android.permission.READ_PHONE_STATE)
AddPermission(android.permission.CALL_PHONE)
AddPermission(android.permission.ACCESS_COARSE_LOCATION)
CreateResourceFromFile(Macro, FirebaseAnalytics.GooglePlayBase)
CreateResourceFromFile(Macro, FirebaseAnalytics.Firebase)
CreateResourceFromFile(Macro, FirebaseNotifications.FirebaseNotifications)
CreateResourceFromFile(Macro, FirebaseAnalytics.FirebaseAnalytics)
CreateResourceFromFile(Macro, FirebaseAdMob.FirebaseAds)
CreateResourceFromFile(Macro, FirebaseAuth.FirebaseAuth)
'************ Firebase Ads ************
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"/>
)
'************ Firebase Ads (end) ************
'************ Firebase Base ************
CreateResourceFromFile("google-services", "google-services.json")
AddPermission(android.permission.ACCESS_NETWORK_STATE)
AddPermission(android.permission.INTERNET)
AddPermission(android.permission.WAKE_LOCK)
AddPermission(com.google.android.c2dm.permission.RECEIVE)
AddPermission(${applicationId}.permission.C2D_MESSAGE)
AddPermission(com.google.android.finsky.permission.BIND_GET_INSTALL_REFERRER_SERVICE)
AddManifestText( <permission android:name="${applicationId}.permission.C2D_MESSAGE"
  android:protectionLevel="signature" />)
AddApplicationText(
 <receiver
            android:name="com.google.android.gms.measurement.AppMeasurementReceiver"
            android:enabled="true"
            android:exported="false" >
        </receiver>

  <service
            android:name="com.google.android.gms.measurement.AppMeasurementService"
            android:enabled="true"
            android:exported="false" />
        
 <receiver
            android:name="com.google.android.gms.measurement.AppMeasurementInstallReferrerReceiver"
            android:enabled="true"
            android:exported="true"
            android:permission="android.permission.INSTALL_PACKAGES" >
            <intent-filter>
                <action android:name="com.android.vending.INSTALL_REFERRER" />
            </intent-filter>
</receiver>
<service
            android:name="com.google.android.gms.measurement.AppMeasurementJobService"
            android:enabled="true"
            android:exported="false"
            android:permission="android.permission.BIND_JOB_SERVICE" />

 <service android:name="com.google.firebase.components.ComponentDiscoveryService" >
            <meta-data
                android:name="com.google.firebase.components:com.google.firebase.analytics.connector.internal.AnalyticsConnectorRegistrar"
                android:value="com.google.firebase.components.ComponentRegistrar" />
            <meta-data
                android:name="com.google.firebase.components:com.google.firebase.iid.Registrar"
                android:value="com.google.firebase.components.ComponentRegistrar" />
             <meta-data
                android:name="com.google.firebase.components:com.google.firebase.auth.FirebaseAuthRegistrar"
                android:value="com.google.firebase.components.ComponentRegistrar" />
</service>
   <provider
  android:authorities="${applicationId}.firebaseinitprovider"
  android:name="com.google.firebase.provider.FirebaseInitProvider"
  android:exported="false"
  android:initOrder="100" />
 
   <receiver
  android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver"
  android:exported="true"
  android:permission="com.google.android.c2dm.permission.SEND" >
  <intent-filter>
  <action android:name="com.google.android.c2dm.intent.RECEIVE" />
  <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
  <category android:name="${applicationId}" />
  </intent-filter>
  </receiver>
    <receiver
  android:name="com.google.firebase.iid.FirebaseInstanceIdInternalReceiver"
  android:exported="false" />


  <service
  android:name="com.google.firebase.iid.FirebaseInstanceIdService"
  android:exported="true">
  <intent-filter android:priority="-500">
  <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
  </intent-filter>
  </service>
)

'************ Firebase Base (end) ************

ASALES,SOREX or someone else can help me?

Thanks in advance
 
Upvote 0

dibesw

Active Member
Licensed User
Longtime User
I do not know what happened
I tried to test ID and it worked
After I have taken out test ID and it worked the same!!o_O
(after so many times I tried) :(
Code for test is
B4X:
Sub LoadAd
    BannerAd.Initialize2("BannerAd", "ca-app-pub-9301620xxxxxxxxxx/8543266512", BannerAd.SIZE_SMART_BANNER)
    BannerAd.LoadAdWithTestDevice("CAD8007B065E0B86EF3C52DFD5558E21")
    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)
    'Activity.AddView(BannerAd, 0, 0,  320dip, 50dip)
   'BannerAd.LoadAd
End Sub

I hope it serves somebody;)
 
Last edited:
Upvote 0
Top