Spright
Active Member
I'm trying to figure out how to handle the ads correctly, I get this message in the log now, Is this message really supposed to be in the background or should you handle it somehow and avoid loading ad? I include the log output that i am reffering to at the top of the code! Otherwise, thanks for an amazing platform to develop software on!
It does need the libgdx library that is available on the forum. Otherwise it uses standard right out of the box.
It does need the libgdx library that is available on the forum. Otherwise it uses standard right out of the box.
B4X:
#MultiDex: True
#IF THEN
** Activity (main) Resume **
sensor listener setup
resumed
GOT REWARD! NOW YOU HAVE COLLECTED THIS MANY COINS:
ad closed
Failed to load RewardedAd: {
"Code": 0,
"Message": "Error while connecting to ad server: Unable to resolve host \"googleads.g.doubleclick.net\": No address associated with hostname",
"Domain": "com.google.android.gms.ads",
"Cause": "null",
"Response Info": {
"Response ID": "null",
"Mediation Adapter Class Name": "",
"Adapter Responses": [],
"Response Extras": {}
}
}
#End If
#Region Project Attributes
#FullScreen: True
#IncludeTitle: False
#ApplicationLabel: Demo
#VersionCode: 1
#VersionName:
#SupportedOrientations: sensorLandscape
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#End Region
Sub Process_Globals
End Sub
Sub Globals
Dim GL As lgGL
Dim lGdx As LibGDX
Dim IP As lgInputProcessor
Dim Batch As lgSpriteBatch
Dim texsheet As lgTexture
Dim adwanted As Boolean = True
Dim AdView1 As AdView
Dim tm As Timer
Dim Camera As lgOrthographicCamera
Type MatrixValues(a As Float, b As Float, c As Float, d As Float, tx As Float, ty As Float)
End Sub
Sub Activity_Create(FirstTime As Boolean)
Dim Config As lgConfiguration
Config.useAccelerometer = False
Config.useCompass = False
lGdx.Initialize2(Config, "LG")
AdView1.Initialize2("BannerAd", "ca-app-pub-3940256099942544/6300978111", AdView1.SIZE_SMART_BANNER)
Activity.AddView(AdView1, 0, 100%y - 50dip, 100%x, 50dip)
AdView1.LoadAd
tm.Initialize("timer",4000*2)
tm.Enabled = True
End Sub
Sub Activity_Resume
Starter.RewardAd.Callback = Me
If AdView1.IsInitialized Then AdView1.resume
If lGdx.IsInitialized Then lGdx.Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
If AdView1.IsInitialized Then AdView1.pause
If lGdx.IsInitialized Then lGdx.Pause
End Sub
Sub Activity_Destroy
End Sub
Sub LG_Create
Batch.Initialize
IP.Initialize("IP")
texsheet.Initialize("sprite.png")
Camera.Initialize
Camera.SetToOrtho(False)
End Sub
Sub LG_Resume
End Sub
Sub LG_Pause
End Sub
Sub LG_Dispose
If texsheet.IsInitialized Then texsheet.dispose
If Batch.IsInitialized Then Batch.dispose
End Sub
Sub LG_Render
GL.glClearColor(0, 0, 1, 1)
GL.glClear(GL.GL10_COLOR_BUFFER_BIT)
Camera.Update
Batch.ProjectionMatrix = Camera.Combined
Batch.Begin
Dim X, Y As Int
For i = 1 To 99
X = Rnd(0,999)
Y = Rnd(0,499)
Batch.DrawTex2(texsheet, X, Y, 100dip, 100dip)
Next
Batch.End
End Sub
Sub IP_TouchDown(ScreenX As Int, ScreenY As Int, Pointer As Int) As Boolean
Return True
End Sub
Sub ToastMsg_Show(Text As Object)
ToastMessageShow(Text, True)
End Sub
Sub RewardAd_Rewarded (Item As Object)
Log("GOT REWARD! NOW YOU HAVE COLLECTED THIS MANY COINS:")
End Sub
Sub RewardAd_AdClosed
Log("ad closed")
End Sub
Sub timer_Tick
If adwanted = True Then
If Starter.RewardAd.Ready Then
Starter.RewardAd.Show
adwanted = False
adwanted = True
Else
' No ad is available, handle the error
HandleAdLoadError
End If
End If
Log("TIMER!")
End Sub
Sub HandleAdLoadError
ToastMessageShow("Failed to load rewarded ad. Please check your internet connection.", True)
' Additional actions here e.g. disabling ad-related functionality or providing alternative content
End Sub