Android Question [SOLVED]Need help with StartActivityForResult

Picena Informatica

Active Member
Licensed User
Longtime User
I need to emulate in B4A the calling of following code.

Code: Copy
Intent collectPaymentIntent = new Intent(Intents.ACTION_COLLECT_PAYMENT);
collectPaymentIntent.putExtra(Intents.INTENT_EXTRAS_PAYMENT, payment);
startActivityForResult(collectPaymentIntent, COLLECT_PAYMENT_REQUEST);

With
Code: Copy
jo.RunMethod("startActivityForResult", Array As Object(ion, i))
i cannot pass the paramenter "COLLECT_PAYMENT_REQUEST"

Can someone help me?

Thanks in advance
 
No. This is for implement Poynt SmartPos. I can do it with Android Studio and java but i need more efficient tool to develop.
 
Upvote 0
No. This is for implement Poynt SmartPos. I can do it with Android Studio and java but i need more efficient tool to develop.
Oh - ok . Not sure if you can do it without a b4a library wrapper can you? Or is that what you're using?

- Colin.
 
Upvote 0
I do not need a wrapper. All job is done with startactivityforresult. With java i can pass COLLECT_PAYMENT_REQUEST (an int) as second parameter of startactivityforresult and get the result.
 
Upvote 0
Excuse me for bold. If i do not send the constant i do not get the service. There are several constants for several services.

Best regards
 
Upvote 0
Thi is all the code i tested with Android Studio (it works, shows the external activity and get the result):
Code: Copy
package com.example.myapplication;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import android.util.Log;

import java.util.UUID;

import android.content.Intent;

import co.poynt.os.model.Intents;
import co.poynt.os.model.Payment;
import co.poynt.os.model.PaymentStatus;

public class MainActivity extends AppCompatActivity {

    private static final String TAG = MainActivity.class.getSimpleName();
    private static final int COLLECT_PAYMENT_REQUEST = 13132;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Button button = (Button) findViewById(R.id.button1);
        button.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                // Do something in response to button click

                //Button button = (Button) findViewById(R.id.button1);
                //button.setText("Premuto");

                Payment payment = new Payment();
                String referenceId = UUID.randomUUID().toString();
                payment.setReferenceId(referenceId);
                payment.setAmount(10);
                payment.setCurrency("EUR");

                Intent collectPaymentIntent = new Intent(Intents.ACTION_COLLECT_PAYMENT);
                collectPaymentIntent.putExtra(Intents.INTENT_EXTRAS_PAYMENT, payment);
                startActivityForResult(collectPaymentIntent, COLLECT_PAYMENT_REQUEST);

            }
        });
    }


    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        // Check which request we're responding to
        if (requestCode == COLLECT_PAYMENT_REQUEST) {
            // Make sure the request was successful
            if (resultCode == MainActivity.RESULT_OK) {
                if (data != null) {
                    Payment payment = data.getParcelableExtra(Intents.INTENT_EXTRAS_PAYMENT);
                    Log.d(TAG, "Received onPaymentAction from PaymentFragment w/ Status("
                            + payment.getStatus() + ")");
                    if (payment.getStatus().equals(PaymentStatus.COMPLETED)) {
                        Toast.makeText(this, "Payment Completed", Toast.LENGTH_LONG).show();
                    } else if (payment.getStatus().equals(PaymentStatus.AUTHORIZED)) {
                        Toast.makeText(this, "Payment Authorized", Toast.LENGTH_LONG).show();
                    } else if (payment.getStatus().equals(PaymentStatus.CANCELED)) {
                        Toast.makeText(this, "Payment Canceled", Toast.LENGTH_LONG).show();
                    } else if (payment.getStatus().equals(PaymentStatus.FAILED)) {
                        Toast.makeText(this, "Payment Failed", Toast.LENGTH_LONG).show();
                    } else if (payment.getStatus().equals(PaymentStatus.REFUNDED)) {
                        Toast.makeText(this, "Payment Refunded", Toast.LENGTH_LONG).show();
                    } else if (payment.getStatus().equals(PaymentStatus.VOIDED)) {
                        Toast.makeText(this, "Payment Voided", Toast.LENGTH_LONG).show();
                    } else {
                        Toast.makeText(this, "Payment Completed", Toast.LENGTH_LONG).show();
                    }
                }
            } else if (resultCode == MainActivity.RESULT_CANCELED) {
                Toast.makeText(this, "Payment Canceled", Toast.LENGTH_LONG).show();
            }
        }
    }
}

In additional jar there are only the constants and the Payment object.
Without the second parameter of startActivityForResult the external activity called by intent do not works.

Best regards
 
Upvote 0
I cannot test it now, but i remeber you that there are several constant for several services. Another constant i must use i 13133.

I can do the test in the afternoon and give you the answer.

Best regards
 
Upvote 0
My apologies, of course you were right, it was my mistake to get the name of the intent in Basic code. Everything works, thanks to Erel and B4A.
Now I try to add "Wait For" to wait for "ion_Event".

Thank you for the time spent for me.

Best Regards
 
Upvote 0
So how did you emulate this code in B4A?
In particular, how did you add the second parameter to: startActivityForResult?

Code: Copy
Intent collectPaymentIntent = new Intent(Intents.ACTION_COLLECT_PAYMENT);
collectPaymentIntent.putExtra(Intents.INTENT_EXTRAS_PAYMENT, payment);
startActivityForResult(collectPaymentIntent, COLLECT_PAYMENT_REQUEST);
 
Upvote 0
Back
Top