Android Question Problem with StartActivityForResult return result

TheMightySwe

Active Member
Licensed User
Longtime User
Hi,

We have a java app that connects to a Cardterminal that has the name "se.iqpd.checkout.companion". We start that in B4A with the following code.

B4X:
Dim ISMP_Intent As Intent
    Dim InstalledPackages As PackageManager
    ISMP_Intent = InstalledPackages.GetApplicationIntent("se.iqpd.checkout.companion")
    ISMP_Intent.PutExtra("JobId","31271")
    ISMP_Intent.PutExtra("TransactionType","Purchase")
    ISMP_Intent.PutExtra("Amount",NumberFormat2(SubTotal_Double-SubTotal_Discount_Double,1,2,2,False))
    StartActivityForResult(ISMP_Intent)

We send the return with following JAVA-code

B4X:
Intent output = new Intent();
            output.putExtra("RESULT", RESULT_OK);
[....] ' Lots of  otherresultdata that we cant post because of confidentiallity agreement  
            getParent().setResult(Activity.RESULT_OK, output);
            finish();


But in B4A we get a error, nothing returns.



Why is that, anyone knows?

// TMS
 

TheMightySwe

Active Member
Licensed User
Longtime User
Can you upload your code?

This is the B4A part.

B4X:
#Region Companion

Sub GetBA As Object

   Dim jo As JavaObject
   Dim cls As String = Me
   cls = cls.SubString("class ".Length)
   jo.InitializeStatic(cls)
   Return jo.GetField("processBA")
  
End Sub

Sub StartActivityForResult(CompanionIntent As Intent)
   Dim jo As JavaObject = GetBA
   Companion = jo.CreateEvent("anywheresoftware.b4a.IOnActivityResult", "Companion", Null)
   jo.RunMethod("startActivityForResult", Array As Object(Companion, CompanionIntent))
End Sub

Sub Companion_Event(MethodName As String, Args() As Object) As Object

    Dim ResultCode As Int
    Dim ResultIntent As Intent
   
    ResultCode = Args(0)
    ResultIntent = Args(1)
   
    Return Null

End Sub

Sub IsCompanionAvailible As Boolean

    If IsIQPDCompanionApplicationInstalled = True AND IsPayexCompanionServiceInstalled = True Then
        ISMP.IsAvailible = True
        Return True
    Else
        ISMP.IsAvailible = False
        Return False
    End If

End Sub

Sub IsIQPDCompanionApplicationInstalled As Boolean

    Dim InstalledPackages As PackageManager
    InstalledPackages.GetInstalledPackages()
   
    Dim Packages As List
    Packages = InstalledPackages.GetInstalledPackages
   
    For i = 0 To Packages.Size - 1
        If Packages.Get(i) = "se.iqpd.checkout.companion" Then Return True
    Next
   
    Return False

End Sub

Sub IsPayexCompanionServiceInstalled As Boolean

    Dim InstalledPackages As PackageManager
    InstalledPackages.GetInstalledPackages()
   
    Dim Packages As List
    Packages = InstalledPackages.GetInstalledPackages
    For i = 0 To Packages.Size - 1
        If Packages.Get(i) = "com.ingenico.pclservice" Then Return True
    Next
   
    Return False

End Sub

Sub ISMPCompanionDoPurchase

    If IsCompanionAvailible = False Then
        Return
    End If

    If IsNumber(SubTotal_Double-SubTotal_Discount_Double) = False Then Return
   
    If CodeSnippets.IsNegative(SubTotal_Double-SubTotal_Discount_Double) = True Then Return

    Dim ISMP_Intent As Intent
    Dim InstalledPackages As PackageManager
    ISMP_Intent = InstalledPackages.GetApplicationIntent("se.iqpd.checkout.companion")
    ISMP_Intent.PutExtra("JobId","31271")
    ISMP_Intent.PutExtra("TransactionType","Purchase")
    ISMP_Intent.PutExtra("Amount",NumberFormat2(SubTotal_Double-SubTotal_Discount_Double,1,2,2,False))
    StartActivityForResult(ISMP_Intent)

End Sub

Sub ISMPCompanionDoCashback

    If IsCompanionAvailible = False Then
        Return
    End If
   
    If IsNumber(SubTotal_Double-SubTotal_Discount_Double) = False Then Return
    If IsNumber(SubTotal_Cashback_Double) = False Then Return

    If CodeSnippets.IsNegative(SubTotal_Double-SubTotal_Discount_Double) = True Then Return
    If CodeSnippets.IsNegative(SubTotal_Cashback_Double) = True Then Return

    Dim ISMP_Intent As Intent
 
    Dim InstalledPackages As PackageManager
    ISMP_Intent = InstalledPackages.GetApplicationIntent("se.iqpd.checkout.companion")

    ISMP_Intent.PutExtra("JobId","0")
    ISMP_Intent.PutExtra("TransactionType","Cashback")
    ISMP_Intent.PutExtra("Amount",NumberFormat2(SubTotal_Double-SubTotal_Discount_Double,1,2,2,False))
    ISMP_Intent.PutExtra("ExtraAmount",NumberFormat2(SubTotal_Cashback_Double,1,2,2,False))
    StartActivityForResult(ISMP_Intent)

End Sub

Sub ISMPCompanionDoRefund

    If IsCompanionAvailible = False Then
        Return
    End If

    If IsNumber(CodeSnippets.ConvertToPositive(SubTotal_Double)) = False Then Return

   Dim ISMP_Intent As Intent
  
   Dim InstalledPackages As PackageManager
   ISMP_Intent = InstalledPackages.GetApplicationIntent("se.iqpd.checkout.companion")
   ISMP_Intent.PutExtra("JobId","0")
   ISMP_Intent.PutExtra("TransactionType","Refund")
   ISMP_Intent.PutExtra("Amount",CodeSnippets.ConvertToPositive(SubTotal_Double))
  
   StartActivityForResult(ISMP_Intent)

End Sub

Sub ISMPCompanionDoReversal

    If IsCompanionAvailible = False Then
        Return
    End If

   Dim ISMP_Intent As Intent
   Dim InstalledPackages As PackageManager
   ISMP_Intent = InstalledPackages.GetApplicationIntent("se.iqpd.checkout.companion")
   ISMP_Intent.PutExtra("JobId","0")
   ISMP_Intent.PutExtra("TransactionType","Reversal")
   StartActivityForResult(ISMP_Intent)

End Sub

#End Region

Unfortuanally you need hardware to run the JAVA part, but i'll ask our JAVA-guy to upload the JAVA part.
 
Upvote 0

TheMightySwe

Active Member
Licensed User
Longtime User
B4X:
  Log(Args)
    Log("Args length : " & Args.Length)

Gives

[Ljava.lang.Object;@2168f368
Args length : 2

Error is

 
Upvote 0

TheMightySwe

Active Member
Licensed User
Longtime User
This is the errors that we get when we try to access the object containing the result. But since we get ArrayIndexOutOfBoundsException it seems like we dont send anything back from our java application.
 
Upvote 0

TheMightySwe

Active Member
Licensed User
Longtime User
Yes and that is something we dont get, returns length 2 but still get ArrayIndexOutOfBoundsException when we try to access the array.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…