Android Code Snippet Advertising id

Discussion in 'Code Snippets' started by Erel, Jan 3, 2019.

  1. Erel

    Erel Administrator Staff Member Licensed User

    1. Add a reference to FirebaseAdMob.
    2. Add to manifest editor:
    Code:
    CreateResourceFromFile(Macro, FirebaseAnalytics.GooglePlayBase)
    3. Add to main module:
    Code:
    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
    Usage example:
    Code:
    Wait For (GetAdvertisingId) Complete (Id As String)
    If Id <> "" Then
       
    Log(Id)
    End If
    Q: What is the advertising id?

    A: https://support.google.com/googleplay/android-developer/answer/6048248?hl=en

    The IDE will show a warning about FirebaseAdMob not being used. You can discard this warning with:
    Code:
    #IgnoreWarnings: 32
     
    Last edited: Jun 4, 2019
    GMan, MarcoRome, Star-Dust and 3 others like this.
  2. Star-Dust

    Star-Dust Expert Licensed User

    Thanks Erel and really very useful.
    I had tried to do something like this by copying the example Java code but without result.
     
  3. GMan

    GMan Well-Known Member Licensed User

  4. Erel

    Erel Administrator Staff Member Licensed User

    I've updated the link.
     
    GMan likes this.
  5. Filippo

    Filippo Expert Licensed User

    The procedure is clear, what I do not understand is what do I do with the "advertising id"?

    Code:
    Wait For (GetAdvertisingId) Complete (Id As String)
    If Id <> "" Then
       
    Log(Id)
    End If
     
  6. Erel

    Erel Administrator Staff Member Licensed User

  7. Filippo

    Filippo Expert Licensed User

    Maybe I do not see the forest for the trees (German proverb). :(
    My question is: where do I build this ID, should the admod-id be replaced with it?
     
  8. Star-Dust

    Star-Dust Expert Licensed User

    I would use it as alternative to identifying ID.
    The user rarely resets it because he often does not even know it exists.
    So it could be used to identify the device.

    PS. I did not understand the proverb
     
    Last edited: Feb 28, 2019
    Erel and Filippo like this.
  9. Filippo

    Filippo Expert Licensed User

    "Non vedo la foresta di fronte a tanti alberi." :p
     
    Star-Dust likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice