Android Question Help in APP 2 APP

holzhacker

Member
Licensed User
Longtime User
Friends, I have little experience with B4A,

Can anyone help me use this code that refers to the integration with Brazilian payment APP (www.pagseguro.com.br)

integration: http://download.uol.com.br/pagseguro/docs/pagseguro-app2app.pdf

Below is the code that checks whether the PagSeguro application is installed on mobile:

---EXAMPLE CODE-----------------------
private boolean checkIfAppIsInstalled() {
PackageManager pm = getPackageManager();
boolean installed = false;

try {
pm.getPackageInfo(PAG_SEGURO_PACKAGE_NAME, PackageManager.GET_ACTIVITIES);
installed=true;
} catch (PackageManager.NameNotFoundException e) {
installed=false;
}
return installed;
}​
------------------------
This is OK, I made that way I can check if the application is installed.

--MY CODE IN B4A-------------------------
Sub Process_Globals
Dim PAG_SEGURO_PACKAGE_NAME As String = "br.com.uol.ps"
Dim PAG_SEGURO_CLASS_NAME As String = "br.com.uol.ps.app.MainActivity"
Dim FLAG_APP_PAYMENT_VALUE As String = "FLAG_APP_PAYMENT_VALUE"
Dim REQUEST_CODE As Int = 123
Dim paymentValue As BigDecimal

paymentValue.Initialize("10.99")

...


Sub Activity_Create(FirstTime As Boolean)
Dim pm As PackageManager
Dim packages As List
packages = pm.GetInstalledPackages
For i = 0 To packages.Size - 1
If packages.Get(i) = PAG_SEGURO_PACKAGE_NAME Then
Log("PagSeguro is installed. Package: "&packages.Get(i))
End If

Next​
------------------------

Code that calls the application and pass the value of the sale, here is what I'm having trouble at the moment, I can CALL the application, but can not pass the values to him.

---EXAMPLE CODE-----------------------
private static final String PAG_SEGURO_PACKAGE_NAME = "br.com.uol.ps";
private static final String PAG_SEGURO_CLASS_NAME = "br.com.uol.ps.app.MainActivity";
private static final String FLAG_APP_PAYMENT_VALUE = "FLAG_APP_PAYMENT_VALUE";
private static final int REQUEST_CODE = 123; // It may be the number of your choice

BigDecimal paymentValue = new BigDecimal(“ 10.99 ”) ;

Intent it = new Intent(Intent.ACTION_MAIN);
it.setClassName(PAG_SEGURO_PACKAGE_NAME, PAG_SEGURO_CLASS_NAME); // Intent will be called.
it.putExtra(FLAG_APP_PAYMENT_VALUE, paymentValue); // Sale Value.

try {
startActivityForResult(it, REQUEST_CODE); // Calls PagSeguro application.
} catch (ActivityNotFoundException e) {
Toast.makeText(getApplicationContext(), "Aplicativo PagSeguro não instalado", Toast.LENGTH_SHORT).show();
}​
------------------------

--MY CODE IN B4A-------------------------
Sub ButtonPaymment_Click
Dim My_Intent As Intent
Dim InstalledPackages As PackageManager

My_Intent = InstalledPackages.GetApplicationIntent(PAG_SEGURO_PACKAGE_NAME)
My_Intent.PutExtra(PAG_SEGURO_PACKAGE_NAME, PAG_SEGURO_CLASS_NAME)
My_Intent.PutExtra(FLAG_APP_PAYMENT_VALUE, paymentValue)
My_Intent.PutExtra(REQUEST_CODE, 123)

...
StartActivityForResult(ISMP_Intent)
------------------------

Could someone please help me in any way?
 

astf

Member
Licensed User
Longtime User
How can i implement this in B4A?

B4X:
    Dim in As Intent
    in.Initialize(in.ACTION_MAIN,"")

    in.SetComponent("br.com.uol.ps")
'or
    in.SetComponent("br.com.uol.ps.app")

    in.PutExtra("FLAG_APP_PAYMENT_VALUE",10.00)
    StartActivity(in)

return "Complete action using" and show me a list of apps!!!
but the app i want isn't on that list
https://postimg.org/image/90wpjfvwn/

B4X:
private boolean checkIfAppIsInstalled() {
    PackageManager pm = getPackageManager();
    boolean installed = false;

    try {
        pm.getPackageInfo(PAG_SEGURO_PACKAGE_NAME,PackageManager.GET_ACTIVITIES);
        installed = true;
    } catch (PackageManager.NameNotFoundException e) {
        installed = false;
    }

    return installed;
}


private static final String PAG_SEGURO_PACKAGE_NAME = "br.com.uol.ps";
private static final String PAG_SEGURO_CLASS_NAME = "br.com.uol.ps.app.MainActivity";
private static final String FLAG_APP_PAYMENT_VALUE = "FLAG_APP_PAYMENT_VALUE";
private static final int REQUEST_CODE = 123;
BigDecimal paymentValue = new BigDecimal(“10.99”);

    Intent it = new Intent(Intent.ACTION_MAIN);

    it.setClassName(PAG_SEGURO_PACKAGE_NAME, PAG_SEGURO_CLASS_NAME); // Intent que será chamada.
    it.putExtra(FLAG_APP_PAYMENT_VALUE, paymentValue); // Valor da venda.

    try {
        startActivityForResult(it, REQUEST_CODE); // Chama o aplicativo do PagSeguro.
    } catch (ActivityNotFoundException e) {
        Toast.makeText(getApplicationContext(), "Aplicativo PagSeguro não instalado", Toast.LENGTH_SHORT).show();
    }



private static final String FLAG_RESULT_ERROR_CODE = "FLAG_RESULT_ERROR_CODE";
private static final String FLAG_RESULT_ERROR_MESSAGE ="FLAG_RESULT_ERROR_MESSAGE";

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == RESULT_CANCELED) {
        //TODO: Apresentar mensagem de erro ao usuário informando que a operação foi cancelada
    } else if (resultCode == RESULT_OK) {

        if (data.hasExtra(FLAG_RESULT_ERROR_MESSAGE)) {
            int errorCode = data.getIntExtra(FLAG_RESULT_ERROR_CODE, 0);
            String errorMessage = data.getStringExtra(FLAG_RESULT_ERROR_MESSAGE);
        } else {

            String transactionCode = data.getStringExtra(FLAG_TRANSACTION_CODE);
            String paymentMethod = data.getStringExtra(FLAG_PAYMENT_METHOD);
            String cardBrand = data.getStringExtra(FLAG_CARD_BRAND);
            String cardHolder = data.getStringExtra(FLAG_CARD_HOLDER);
            BigDecimal paymentAmount = (BigDecimal)
       
            data.getSerializableExtra(FLAG_PAYMENT_AMOUNT, 0);
            int installmentNumber = data.getIntExtra(FLAG_INSTALLMENT_NUMBER,0);
            BigDecimal installmentAmount = (BigDecimal)
            data.getSerializableExtra(FLAG_PAYMENT_INSTALLMENT, 0);

            Calendar time = (Calendar)
            data.getSerializableExtra(FLAG_PAYMENT_TIME);
        }
    }
}
 
Last edited:
Upvote 0
Top