Android Question Error during compile Receiver Firebase [SOLVED]

AHilberink

Active Member
Licensed User
Longtime User
Hi,

During compiling I got an error:
B4X:
Compileren gegenereerde Java code.    Error
B4A line: 19
End Sub
javac 1.8.0_371
src\ciris\chauffeur\firebasemessaging.java:344: error: incompatible types: firebasemessaging cannot be converted to Context
                       String id = AdvertisingIdClient.getAdvertisingIdInfo(mostCurrent).getId();
                                                                            ^

This is the code I use:
B4X:
Sub GetAdvertisingId As ResumableSub
    Dim jo As JavaObject = Me
    jo.RunMethod("GetAdvertisingId", Null)
    Wait For AdvertisingId_Ready (Success As Boolean, Id As String)
    If (Id=Null Or Id="" Or Id="000000000000000000000") Then Id=EigenFuncties.RandomString(21)
    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

Using this code within the Starter Service there is no error.

Someone can help? Need more info: please let me know.

Kind regards,
André
 
Solution
B4X:
Sub GetAdvertisingId As ResumableSub
    Dim jo As JavaObject = Me
    Dim ctxt As JavaObject
    ctxt.InitializeContext
    jo.RunMethod("GetAdvertisingId", Array(ctxt))
    Wait For AdvertisingId_Ready (Success As Boolean, Id As String)
    If Success Then
        Return Id
    Else
        Log(LastException)
        Return ""
    End If
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(final android.content.Context context) {
   BA.runAsync(processBA, mostCurrent, "advertisingid_ready", new Object[] {false, ""}
       , new Callable<Object[]>() {...

Erel

B4X founder
Staff member
Licensed User
Longtime User
B4X:
Sub GetAdvertisingId As ResumableSub
    Dim jo As JavaObject = Me
    Dim ctxt As JavaObject
    ctxt.InitializeContext
    jo.RunMethod("GetAdvertisingId", Array(ctxt))
    Wait For AdvertisingId_Ready (Success As Boolean, Id As String)
    If Success Then
        Return Id
    Else
        Log(LastException)
        Return ""
    End If
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(final android.content.Context context) {
   BA.runAsync(processBA, mostCurrent, "advertisingid_ready", new Object[] {false, ""}
       , new Callable<Object[]>() {
                   @Override
                   public Object[] call() throws Exception {
                       String id = AdvertisingIdClient.getAdvertisingIdInfo(context).getId();
                       return new Object[] {true, id};
                   }
               }); }
#End If
 
Upvote 1
Solution

AHilberink

Active Member
Licensed User
Longtime User
B4X:
Sub GetAdvertisingId As ResumableSub
    Dim jo As JavaObject = Me
    Dim ctxt As JavaObject
    ctxt.InitializeContext
    jo.RunMethod("GetAdvertisingId", Array(ctxt))
    Wait For AdvertisingId_Ready (Success As Boolean, Id As String)
    If Success Then
        Return Id
    Else
        Log(LastException)
        Return ""
    End If
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(final android.content.Context context) {
   BA.runAsync(processBA, mostCurrent, "advertisingid_ready", new Object[] {false, ""}
       , new Callable<Object[]>() {
                   @Override
                   public Object[] call() throws Exception {
                       String id = AdvertisingIdClient.getAdvertisingIdInfo(context).getId();
                       return new Object[] {true, id};
                   }
               }); }
#End If

Thanks. This works perfect.
 
Upvote 0
Top