Android Question HELP TO TRANSLATE A CODE TO B4A

JUAN CARLOSORDOÑEZ

Member
Licensed User
Longtime User
Hello
They asked me to adapt a code to B4A but I can't find a solution to something.
It is about making an app that communicates by INTENT with another that in turn interfaces with some payment devices. They give me the intent parameters but I have not received a response from the other app. Please, Can someone help me? I attach the example code and the code translated to B4A
Please tell me how to repay your valuable help. Thanks in advance
 

Attachments

  • CODIGO.TXT
    3.6 KB · Views: 228

drgottjr

Expert
Licensed User
Longtime User
unfortunately, i find the code a little difficult to follow, but
judging by your post, it sounds like you may be looking for
StartActivityForResult

it sounds like app #2 is launched by your intent and then you're looking
for something back from that app.
 
Upvote 0

tigrot

Well-Known Member
Licensed User
Longtime User
B4X:
Sub Process_Globals
    'DATAFONOS
    Dim INPUT As String
    Dim MONTO,VR_IVA,VR_IMPOCONSUMO,BASE_IVA,BASE_IMPOCONSUMO,BASE_DEVOLUCION As Double
    Public  PACKAGE = "rbm.pax.wimobile.com.rbmappcomercioswm" As String
    Public  SEND_COMERCIOS ="rbm.pax.wimobile.com.rbmappcomercioswm.features.mainmenu.ui.MainMenuActivity" As String
    Public  packageName = "package" As String
    Public  data_input = "data_input" As String
End Sub

Sub Globals
    Dim etiqueta3, etiqueta4,LBLAction,LBLACTION_SEND,LBLExtrasToString,LBLGetData,LBLGetExtra,LBLPACKAGE,LBLPACKAGENAME,LBLSENDCOMERCIOS As Label
    Dim boton,BTNENVIAR As Button
    Private TXTPACKAGE,TXTSENDCOMERCIOS,TXTPACKAGENAME,TXTExtrasToString,TXTAction,TXTGetExtra,TXTACTION_SEND,TXTGetData As EditText
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("DATAFONO")
    TXTPACKAGE.Text=PACKAGE
    TXTSENDCOMERCIOS.Text=SEND_COMERCIOS
    TXTPACKAGENAME.text=packageName
End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
End Sub

Private Sub BTNENVIAR_Click
    MONTO=10000
    VR_IMPOCONSUMO=0
    BASE_IVA=Round2(MONTO/1.19,2)
    VR_IVA=Round2(MONTO-BASE_IVA,2)
    BASE_IMPOCONSUMO=0
    BASE_DEVOLUCION=0
    
    INPUT = "{" & CRLF & "TipoTransaccion: 1" & CRLF & "properties: {"& CRLF & "Monto: " & MONTO & "," & CRLF & "Iva: "& VR_IVA & "," & CRLF & "Inc: " & VR_IMPOCONSUMO & "," & CRLF & "Monto_base_iva: " & BASE_IVA&"," & CRLF & "Monto_base_inc: "&BASE_IMPOCONSUMO & "," & CRLF & "Base_devolucion: " & BASE_DEVOLUCION & CRLF & "}" & CRLF & "}"
    
    Msgbox("JSON: "& INPUT,"Atención")
    Dim i As Intent
    i.Initialize("Intent.ACTION_SEND","")
    i.PutExtra("data_input",INPUT)
    i.PutExtra("packageName",packageName)
    StartActivityForResult(i)
End Sub
Sub StartActivityForResult(i As Intent)
    Dim jo As JavaObject = GetBA
    Dim ion As Object = jo.CreateEvent(PACKAGE, "ion", Null)
    jo.RunMethod("startActivityForResult", Array As Object(ion, i))
End Sub

Sub GetBA As Object
    Dim jo As JavaObject = Me
    Return jo.RunMethod("getBA", Null)
End Sub

Something like that but you gave me few informations.

Ciao
Mauro
 
Upvote 0

JUAN CARLOSORDOÑEZ

Member
Licensed User
Longtime User
B4X:
Sub Process_Globals
    'DATAFONOS
    Dim INPUT As String
    Dim MONTO,VR_IVA,VR_IMPOCONSUMO,BASE_IVA,BASE_IMPOCONSUMO,BASE_DEVOLUCION As Double
    Public  PACKAGE = "rbm.pax.wimobile.com.rbmappcomercioswm" As String
    Public  SEND_COMERCIOS ="rbm.pax.wimobile.com.rbmappcomercioswm.features.mainmenu.ui.MainMenuActivity" As String
    Public  packageName = "package" As String
    Public  data_input = "data_input" As String
End Sub

Sub Globals
    Dim etiqueta3, etiqueta4,LBLAction,LBLACTION_SEND,LBLExtrasToString,LBLGetData,LBLGetExtra,LBLPACKAGE,LBLPACKAGENAME,LBLSENDCOMERCIOS As Label
    Dim boton,BTNENVIAR As Button
    Private TXTPACKAGE,TXTSENDCOMERCIOS,TXTPACKAGENAME,TXTExtrasToString,TXTAction,TXTGetExtra,TXTACTION_SEND,TXTGetData As EditText
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("DATAFONO")
    TXTPACKAGE.Text=PACKAGE
    TXTSENDCOMERCIOS.Text=SEND_COMERCIOS
    TXTPACKAGENAME.text=packageName
End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
End Sub

Private Sub BTNENVIAR_Click
    MONTO=10000
    VR_IMPOCONSUMO=0
    BASE_IVA=Round2(MONTO/1.19,2)
    VR_IVA=Round2(MONTO-BASE_IVA,2)
    BASE_IMPOCONSUMO=0
    BASE_DEVOLUCION=0
   
    INPUT = "{" & CRLF & "TipoTransaccion: 1" & CRLF & "properties: {"& CRLF & "Monto: " & MONTO & "," & CRLF & "Iva: "& VR_IVA & "," & CRLF & "Inc: " & VR_IMPOCONSUMO & "," & CRLF & "Monto_base_iva: " & BASE_IVA&"," & CRLF & "Monto_base_inc: "&BASE_IMPOCONSUMO & "," & CRLF & "Base_devolucion: " & BASE_DEVOLUCION & CRLF & "}" & CRLF & "}"
   
    Msgbox("JSON: "& INPUT,"Atención")
    Dim i As Intent
    i.Initialize("Intent.ACTION_SEND","")
    i.PutExtra("data_input",INPUT)
    i.PutExtra("packageName",packageName)
    StartActivityForResult(i)
End Sub
Sub StartActivityForResult(i As Intent)
    Dim jo As JavaObject = GetBA
    Dim ion As Object = jo.CreateEvent(PACKAGE, "ion", Null)
    jo.RunMethod("startActivityForResult", Array As Object(ion, i))
End Sub

Sub GetBA As Object
    Dim jo As JavaObject = Me
    Return jo.RunMethod("getBA", Null)
End Sub

Something like that but you gave me few informations.

Ciao
Mauro

In some payment devices there is an app that manages the handling of credit cards.
The provider of that app provided me with the following code for me to transcribe it in B4A
to be able to send some data (json) and his app manages its own and responds to me with some data:

' BELOW EXAMPLE IN ANDROID STUDIO************************
' setResult(Activity.RESULT_OK, i)
' ComponentName cn = new ComponentName(PACKAGE,SEND_COMERCIOS);
' activityMainBinding.input.setText(json);
' i = new Intent(Intent.ACTION_SEND);
' i.setComponent(cn);
' i.putExtra(data_input, json);
' i.putExtra(packageName, getApplicationContext().getPackageName());
' Try {
' startActivityForResult(i, REQUESTCOMERCIOS);
' } Catch (ActivityNotFoundException e) {
' Toast.makeText(getApplicationContext(),getApplicationContext().getString(R.string.not_found_app_bio)
' , Toast.LENGTH_SHORT).show();
' }
'END EXAMPLE *******************

The constants the author gave me are:

Public PACKAGE = "rbm.pax.wimobile.com.rbmappcomercioswm" As String
Public SEND_COMERCIOS ="rbm.pax.wimobile.com.rbmappcomercioswm.features.mainmenu.ui.MainMenuActivity" As String
Public packageName = "package" As String
Public data_input = "data_input" As String

I have tried to make the adjustments but I do not receive a response.
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
Exactly, that's what it's about, some data is sent to app2 and a response is expected from it
did you look at the link? you're missing the event that returns data to you.
 
Upvote 0

tigrot

Well-Known Member
Licensed User
Longtime User
B4X:
Sub Class_Globals
End Sub


Sub Process_Globals
    'DATAFONOS
    Private ion As Object 'listener object for us
    Dim INPUT As String
    Dim MONTO,VR_IVA,VR_IMPOCONSUMO,BASE_IVA,BASE_IMPOCONSUMO,BASE_DEVOLUCION As Double
    Public  PACKAGE As String = "rbm.pax.wimobile.com.rbmappcomercioswm"
    Public SEND_COMERCIOS As String ="rbm.pax.wimobile.com.rbmappcomercioswm.features.mainmenu.ui.MainMenuActivity"
    Public  packageName  As String= "package"
    Public  data_input As String = "data_input"
End Sub

Sub Globals
    Dim etiqueta3, etiqueta4,LBLAction,LBLACTION_SEND,LBLExtrasToString,LBLGetData,LBLGetExtra,LBLPACKAGE,LBLPACKAGENAME,LBLSENDCOMERCIOS As Label
    Dim boton,BTNENVIAR As Button
    Private TXTPACKAGE,TXTSENDCOMERCIOS,TXTPACKAGENAME,TXTExtrasToString,TXTAction,TXTGetExtra,TXTACTION_SEND,TXTGetData As EditText
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("DATAFONO")
    TXTPACKAGE.Text=PACKAGE
    TXTSENDCOMERCIOS.Text=SEND_COMERCIOS
    TXTPACKAGENAME.text=packageName
End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
End Sub

Private Sub BTN_click
    VR_IMPOCONSUMO=0
    BASE_IVA=Round2(MONTO/1.19,2)
    VR_IVA=Round2(MONTO-BASE_IVA,2)
    BASE_IMPOCONSUMO=0
    BASE_DEVOLUCION=0
  
    INPUT = "{" & CRLF & "TipoTransaccion: 1" & CRLF & "properties: {"& CRLF & "Monto: " & MONTO & "," & CRLF & "Iva: "& VR_IVA & "," & CRLF & "Inc: " & VR_IMPOCONSUMO & "," & CRLF & "Monto_base_iva: " & BASE_IVA&"," & CRLF & "Monto_base_inc: "&BASE_IMPOCONSUMO & "," & CRLF & "Base_devolucion: " & BASE_DEVOLUCION & CRLF & "}" & CRLF & "}"
  
    Msgbox("JSON: "& INPUT,"Atención")
    Dim i As Intent
    i.Initialize("Intent.ACTION_SEND","")
    i.PutExtra("data_input",INPUT)
    i.PutExtra("packageName",packageName)
    StartActivityForResult(i)
End Sub
Sub StartActivityForResult(i As Intent)
    Dim jo As JavaObject = GetBA
    Dim ion As Object = jo.CreateEvent(PACKAGE, "ion", Null)
    jo.RunMethod("startActivityForResult", Array As Object(ion, i))
End Sub

Sub GetBA As Object
    Dim jo As JavaObject = Me
    Return jo.RunMethod("getBA", Null)
End Sub'Program code should go into B4XMainPage and other pages.

Sub ion_Event (MethodName As String, Args() As Object) As Object ' in this sub you should get the answer
    'Args(0) is resultCode: -1 is ok
    'Args(1) is the returning intent / result data
    If -1=Args(0) Then
        Dim i As Intent=Args(1)
        Log(i.ExtrasToString) ' this is the results
    End If
    Return Null
End Sub

This is complete code, I cannot test but look at ion_event, here you should get an answer. Include JavaObject library in Pjt.
 
Upvote 0

JUAN CARLOSORDOÑEZ

Member
Licensed User
Longtime User
Hello. I am sure that there is very little left to achieve communication and I greatly appreciate your great help.

1) I tried the code and I get an error on line 73
2) I think the i.SetPackage (PACKAGE) line was missing, I put it on line 60 of the new attached code
3) Attached the MANIFEST, is it correct?

Attached new complete code, error text and MANIFEST

Thanks
 

Attachments

  • NUEVO CODIGO.txt
    2.9 KB · Views: 124
  • ERROR.txt
    1.7 KB · Views: 124
  • MANIFEST.txt
    802 bytes · Views: 112
Upvote 0

JUAN CARLOSORDOÑEZ

Member
Licensed User
Longtime User
Dunno... I can't help, no experience in this matter.
I appreciate the code that you corrected and sent me, it is only the error of line 73. Really thank you for your contribution

Registro conectado a: PAX A910
--------- beginning of main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
Error occurred on line: 73 (Main)
java.lang.RuntimeException: Method: GetBA not found in: COM.DATAFONO.main
at anywheresoftware.b4j.object.JavaObject$MethodCache.getMethod(JavaObject.java:363)
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:120)
at COM.DATAFONO.main._getba(main.java:550)
at COM.DATAFONO.main._startactivityforresult(main.java:516)
at COM.DATAFONO.main._btnenviar_click(main.java:501)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:197)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
at android.view.View.performClick(View.java:5205)
at android.view.View$PerformClick.run(View.java:21162)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5468)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:675)
 
Upvote 0

JUAN CARLOSORDOÑEZ

Member
Licensed User
Longtime User
Capitalisation problem! It should be
B4X:
Return jo.RunMethod("getBA", Null)
Hello. I already corrected but the error remains. Maybe you can help me. There is not much left. It is about making an app that sends a json file to another that manages payment devices. The second app processes and responds affirmatively or negatively with the credit card payment process. The provider of that other app gave me some parameters but I have not yet been able to communicate.
Thanks in advance
 

Attachments

  • NUEVO CODIGO.txt
    2.9 KB · Views: 106
  • ERROR.txt
    1.7 KB · Views: 120
  • MANIFEST.txt
    802 bytes · Views: 108
Upvote 0

agraham

Expert
Licensed User
Longtime User
I did not correct it but in the b4a I did and it gave me the same error
There is no pount in posting code other than that giving the problem, it just wastes everybody's time. I don't see how you can have that same error if you have the correct name for "getBA".
 
Upvote 0

JUAN CARLOSORDOÑEZ

Member
Licensed User
Longtime User
I'm very sorry, I attached the file that was not.
The corrected code that continues to generate the error is this:

#Region Project Attributes
#ApplicationLabel: DATAFONO
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Class_Globals
End Sub


Sub Process_Globals
'DATAFONOS
Private ion As Object 'listener object for us
Dim INPUT As String
Dim MONTO,VR_IVA,VR_IMPOCONSUMO,BASE_IVA,BASE_IMPOCONSUMO,BASE_DEVOLUCION As Double
Public PACKAGE As String = "rbm.pax.wimobile.com.rbmappcomercioswm"
Public SEND_COMERCIOS As String ="rbm.pax.wimobile.com.rbmappcomercioswm.features.mainmenu.ui.MainMenuActivity"
Public packageName As String= "package"
Public data_input As String = "data_input"
End Sub

Sub Globals
Dim etiqueta3, etiqueta4,LBLAction,LBLACTION_SEND,LBLExtrasToString,LBLGetData,LBLGetExtra,LBLPACKAGE,LBLPACKAGENAME,LBLSENDCOMERCIOS As Label
Dim boton,BTNENVIAR As Button
Private TXTPACKAGE,TXTSENDCOMERCIOS,TXTPACKAGENAME,TXTExtrasToString,TXTAction,TXTGetExtra,TXTACTION_SEND,TXTGetData As EditText
End Sub

Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("DATAFONO")
TXTPACKAGE.Text=PACKAGE
TXTSENDCOMERCIOS.Text=SEND_COMERCIOS
TXTPACKAGENAME.text=packageName
End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
End Sub

Private Sub BTNENVIAR_click
MONTO=10000
VR_IMPOCONSUMO=0
BASE_IVA=Round2(MONTO/1.19,2)
VR_IVA=Round2(MONTO-BASE_IVA,2)
BASE_IMPOCONSUMO=0
BASE_DEVOLUCION=0

INPUT = "{" & CRLF & "TipoTransaccion: 1" & CRLF & "properties: {"& CRLF & "Monto: " & MONTO & "," & CRLF & "Iva: "& VR_IVA & "," & CRLF & "Inc: " & VR_IMPOCONSUMO & "," & CRLF & "Monto_base_iva: " & BASE_IVA&"," & CRLF & "Monto_base_inc: "&BASE_IMPOCONSUMO & "," & CRLF & "Base_devolucion: " & BASE_DEVOLUCION & CRLF & "}" & CRLF & "}"

Msgbox("JSON: "& INPUT,"Atención")
Dim i As Intent
i.Initialize("Intent.ACTION_SEND","")
i.SetPackage(PACKAGE)
i.PutExtra("data_input",INPUT)
i.PutExtra("packageName",packageName)
StartActivityForResult(i)
End Sub
Sub StartActivityForResult(i As Intent)
Dim jo As JavaObject = GetBA
Dim ion As Object = jo.CreateEvent(PACKAGE, "ion", Null)
jo.RunMethod("startActivityForResult", Array As Object(ion, i))
End Sub

Sub GetBA As Object
Dim jo As JavaObject = Me
Return jo.RunMethod("getBA", Null)
End Sub'Program code should go into B4XMainPage and other pages.

Sub ion_Event (MethodName As String, Args() As Object) As Object ' in this sub you should get the answer
'Args(0) is resultCode: -1 is ok
'Args(1) is the returning intent / result data
If -1=Args(0) Then
Dim i As Intent=Args(1)
Log(i.ExtrasToString) ' this is the results
End If
Return Null
End Sub
 
Upvote 0
Top