Android Question [B4X] [Class] Google Play Age Signals & Implementation in iOS - It is giving me hard time in Android

hatzisn

Expert
Licensed User
Longtime User
I received today an e-mail from Google where it mentions that on January 1st in Texas the app must start checking for Google Play Age Signals.
I tried to build a class according to Google Example and with the help of Gemini but it is giving a very hard time. If someone can get over the mistake I am posting the code so far - obviously a library is needed but I do not know what library to add and import.

B4X:
Sub Class_Globals
    #if b4a
    Private nativeMe As JavaObject
    #end if
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
    #if b4a
    nativeMe = Me
    #end if
End Sub

#if b4a

Public Sub IsAgeRestricted As Int
    Return nativeMe.RunMethod("CheckTheUserForAgeRestrictions", Null)
End Sub

'Install in SDK Manager
'com.google.android.play:age-signals:0.0.2
'
'Add additional Jars
'#AdditionalJar: com.google.android.play:age-signals
'#AdditionalJar: com.google.android.gms:play-services-tasks
'
'Add Manifest Entry
'AddPermission(android.permission.ACCESS_ADSERVICES_AGE_SIGNALS)
'
'<code>
'Dim age As AGESignals
'age.Initialize
'Log(age.IsAgeRestricted)
'</code>
Public Sub Instructions
   
End Sub

#if JAVA

import com.google.android.play.agesignals.AgeSignalsManager;
import com.google.android.play.agesignals.AgeSignalsManagerFactory;
import com.google.android.play.agesignals.AgeSignalsRequest;
import com.google.android.play.agesignals.AgeSignalsResult;
import com.google.android.play.agesignals.model.AgeSignalsVerificationStatus;

public int CheckTheUserForAgeRestrictions() {
   
    // Create an instance of a manager
AgeSignalsManager ageSignalsManager =
    AgeSignalsManagerFactory.create(ApplicationProvider.getApplicationContext());

// Request an age signals check
ageSignalsManager
    .checkAgeSignals(AgeSignalsRequest.builder().build())
    .addOnSuccessListener(
        ageSignalsResult -> {
          // Store the install ID for later...
          String installId = ageSignalsResult.installId();

          if (ageSignalsResult
              .userStatus()
              .equals(AgeSignalsVerificationStatus.SUPERVISED_APPROVAL_DENIED)) {
            return 1;
          } else {
            return 2;
          }
        });
       
return 3;
}
#End If

#else if b4i

'<code>
'Dim age As AGESignals
'age.Initialize
'Log(age.IsAgeRestricted)
'</code>
Public Sub Instructions
   
End Sub

'The age restrictions are set during
'setting the app information in AppStore
'so we return always aproved since the app
'will be downloaded according to age restrictions
Public Sub IsAgeRestricted As Int
    Return 2
End If
#End If
 

hatzisn

Expert
Licensed User
Longtime User
I received today an e-mail from Google where it mentions that on January 1st in Texas the app must start checking for Google Play Age Signals.
I tried to build a class according to Google Example and with the help of Gemini but it is giving a very hard time. If someone can get over the mistake I am posting the code so far - obviously a library is needed but I do not know what library to add and import.

B4X:
Sub Class_Globals
    #if b4a
    Private nativeMe As JavaObject
    #end if
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
    #if b4a
    nativeMe = Me
    #end if
End Sub

#if b4a

Public Sub IsAgeRestricted As Int
    Return nativeMe.RunMethod("CheckTheUserForAgeRestrictions", Null)
End Sub

'Install in SDK Manager
'com.google.android.play:age-signals:0.0.2
'
'Add additional Jars
'#AdditionalJar: com.google.android.play:age-signals
'#AdditionalJar: com.google.android.gms:play-services-tasks
'
'Add Manifest Entry
'AddPermission(android.permission.ACCESS_ADSERVICES_AGE_SIGNALS)
'
'<code>
'Dim age As AGESignals
'age.Initialize
'</code>
Public Sub Instructions
 
End Sub

#if JAVA

import com.google.android.play.agesignals.AgeSignalsManager;
import com.google.android.play.agesignals.AgeSignalsManagerFactory;
import com.google.android.play.agesignals.AgeSignalsRequest;
import com.google.android.play.agesignals.AgeSignalsResult;
import com.google.android.play.agesignals.model.AgeSignalsVerificationStatus;

public int CheckTheUserForAgeRestrictions() {
 
    // Create an instance of a manager
AgeSignalsManager ageSignalsManager =
    AgeSignalsManagerFactory.create(ApplicationProvider.getApplicationContext());

// Request an age signals check
ageSignalsManager
    .checkAgeSignals(AgeSignalsRequest.builder().build())
    .addOnSuccessListener(
        ageSignalsResult -> {
          // Store the install ID for later...
          String installId = ageSignalsResult.installId();

          if (ageSignalsResult
              .userStatus()
              .equals(AgeSignalsVerificationStatus.SUPERVISED_APPROVAL_DENIED)) {
            return 1;
          } else {
            return 2;
          }
        });
     
return 3;
}
#End If

#else if b4i

'<code>
'Dim age As AGESignals
'age.Initialize
'Log(age.IsAgeRestricted)
'</code>
Public Sub Instructions
 
End Sub

'The age restrictions are set during
'setting the app information in AppStore
'so we return always aproved since the app
'will be downloaded according to age restrictions
Public Sub IsAgeRestricted As Int
    Return 2
End If
#End If

It got a little better:

B4X:
Sub Class_Globals
    #if b4a
    Private nativeMe As JavaObject
    #end if
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
    #if b4a
    nativeMe = Me
    #end if
End Sub

#if b4a

Public Sub IsAgeRestricted As Int
    nativeMe.RunMethod("CheckTheUserForAgeRestrictions", Null)
End Sub

'<code>
'Install in SDK Manager
'com.google.android.play:age-signals:0.0.2
'
'Add additional Jars
'#AdditionalJar: com.google.android.play:age-signals
'#AdditionalJar: com.google.android.gms:play-services-tasks
'#AdditionalJar: androidx.test:core
'
'Add Manifest Entry
'AddPermission(android.permission.ACCESS_ADSERVICES_AGE_SIGNALS)
'
'Dim age As AGESignals
'age.Initialize
'age.IsAgeRestricted
'</code>
Public Sub Instructions
   
End Sub

#if JAVA

import com.google.android.play.agesignals.AgeSignalsManager;
import com.google.android.play.agesignals.AgeSignalsManagerFactory;
import com.google.android.play.agesignals.AgeSignalsRequest;
import com.google.android.play.agesignals.AgeSignalsResult;
import com.google.android.play.agesignals.model.AgeSignalsVerificationStatus;
import androidx.test.core.app.ApplicationProvider;
import java.lang.invoke.LambdaMetafactory;

int iRet = -1;

public void CheckTheUserForAgeRestrictions() {

    // Create an instance of a manager
AgeSignalsManager ageSignalsManager =
    AgeSignalsManagerFactory.create(ApplicationProvider.getApplicationContext());

// Request an age signals check
ageSignalsManager
    .checkAgeSignals(AgeSignalsRequest.builder().build())
    .addOnSuccessListener(
        result -> {
          // Store the install ID for later...
          String installId = result.installId();

          if (result
              .userStatus()
              .equals(AgeSignalsVerificationStatus.SUPERVISED_APPROVAL_DENIED)) {
            iRet = 1;
          } else {
            iRet = 2;
          }
        });
}
#End If

#else if b4i

'<code>
'Dim age As AGESignals
'age.Initialize
'Log(age.IsAgeRestricted)
'</code>
Public Sub Instructions
   
End Sub

'The age restrictions are set during
'setting the app information in AppStore
'so we return always aproved since the app
'will be downloaded according to age restrictions
Public Sub IsAgeRestricted As Int
    Return 2
End If
#End If
 
Upvote 0
Top