#Region Project Attributes
#ApplicationLabel: medsite test
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#AdditionalJar: com.google.android.gms:play-services-base
' #AdditionalJar: com.google.android.gms:play-services-location
#BridgeLogger: True
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
Private consreceived As Boolean=False
End Sub
Sub Globals
Private BannerAd As AdView
Private Label1 As Label
Private Label2 As Label
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("main")
Wait For (GetAdvertisingId) Complete (Id As String)
If Id <> "" Then
Log(Id)
Label2.text=Id
End If
End Sub
Sub Activity_Resume
Log("Main resume state: " & Starter.consent.ConsentState&" geography:" & Starter.consent.IsRequestLocationInEeaOrUnknown)
If consreceived Then ConsentStateAvailable
If BannerAd.IsInitialized Then BannerAd.Resume
Label1.Text="Geo: "&Starter.consent.IsRequestLocationInEeaOrUnknown&" State: "&Starter.consent.ConsentState
End Sub
Sub Activity_Pause (UserClosed As Boolean)
If BannerAd.IsInitialized Then BannerAd.Pause
End Sub
Public Sub ConsentStateAvailable
consreceived=True
Label1.Text="By event: Geo: "&Starter.consent.IsRequestLocationInEeaOrUnknown&" State: "&Starter.consent.ConsentState
If Starter.consent.ConsentState = Starter.consent.STATE_UNKNOWN And Starter.consent.IsRequestLocationInEeaOrUnknown Then
Starter.consent.ShowConsentForm("https://www.mysite.com/privacy.html", True, True, True)
Wait For consent_FormResult (Success As Boolean, UserPrefersAdFreeOption As Boolean)
If Success Then
Log($"Consent form result: ${Starter.consent.ConsentState}, AdFree: ${UserPrefersAdFreeOption}"$)
Else
Log($"Error: ${LastException}"$)
End If
End If
BannerAd.Initialize2("BannerAd", "ca-app-pub-1111111111111111/2222222222", 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)
LoadAd
Starter.analytics.SendEvent("Consent", CreateMap ("ConsentState": Starter.consent.ConsentState,"ConsentGeo":Starter.consent.IsRequestLocationInEeaOrUnknown))
End Sub
Sub LoadAd
Dim builder As AdRequestBuilder
builder.Initialize
Dim consent As ConsentManager = Starter.consent
If consent.IsRequestLocationInEeaOrUnknown Then
If consent.ConsentState = consent.STATE_NON_PERSONALIZED Then
builder.NonPersonalizedAds
Else if consent.ConsentState = consent.STATE_UNKNOWN Then
Return
End If
End If
builder.addTestDevice("31F6FB8E34815CF697C342C8AB312170")
BannerAd.LoadAdWithBuilder(builder)
End Sub
Public Sub BannerAd_FailedToReceiveAd(ErrorCode As String)
Log("Banner error: "&ErrorCode)
End Sub
Public Sub BannerAd_ReceiveAd
Log("Banner received an Ad")
End Sub
Public Sub BannerAd_PresentScreen
Log("Banner Ad presented")
End Sub
Public Sub BannerAd_AdScreenDismissed
Log("Banner Ad screen dismissed")
End Sub
Private Sub GetAdvertisingId As ResumableSub
Dim jo As JavaObject = Me
jo.RunMethod("GetAdvertisingId", Null)
Wait For AdvertisingId_Ready (Success As Boolean, Id As String)
Return Id
End Sub
#if Java
import java.util.concurrent.Callable;
import com.google.android.gms.ads.identifier.AdvertisingIdClient;
import com.google.android.gms.ads.identifier.AdvertisingIdClient.Info;
public static void GetAdvertisingId() {
BA.runAsync(processBA, mostCurrent, "advertisingid_ready", new Object[] {false, ""}
, new Callable<Object[]>() {
@Override
public Object[] call() throws Exception {
String id = AdvertisingIdClient.getAdvertisingIdInfo(mostCurrent).getId();
return new Object[] {true, id};
}
}); }
#End If