Quantcast
Channel: Active questions tagged react-native+android - Stack Overflow
Viewing all articles
Browse latest Browse all 29448

how to pass data from java activity to react native

$
0
0

I am unable to pass data from java activity to react native. I am processing a card payment, and when the payment is done, the response is stored in a variable called message. I need to pass this message to my react native code.

// Java module, the data I want to pass is in "message"

    @Override
    public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent data) {
    /*
     *  We advise you to do a further verification of transaction's details on your server to be
     *  sure everything checks out before providing service or goods.
    */
    if (requestCode == RaveConstants.RAVE_REQUEST_CODE && data != null) {
        String message = data.getStringExtra("response"); // this is the data
        Log.d("RAVE",message);
        if (resultCode == RavePayActivity.RESULT_SUCCESS) {
            Toast.makeText(activity, "SUCCESS " + message, Toast.LENGTH_SHORT).show();
        }
        else if (resultCode == RavePayActivity.RESULT_ERROR) {
            Toast.makeText(activity, "ERROR " + message, Toast.LENGTH_SHORT).show();
        }
        else if (resultCode == RavePayActivity.RESULT_CANCELLED) {
            Toast.makeText(activity, "CANCELLED " + message, Toast.LENGTH_SHORT).show();
        }
    }

}

// @ReactMethod

 @ReactMethod
    public void sayHi(Callback errorCallback, Callback successCallback) {
        try{
            int amount = 30;//call.argument("amount");
                        String narration = "Payment for soup";//call.argument("nara");
                        String countryCode = "NG"; //call.argument("countryCode");
                        String currency =  "NGN"; //call.argument("currency");
                        String amountText = "50";//call.argument("amountText");
                        String email = "hjjjkdf.com";//call.argument("email");
                        String name = "Danny";//call.argument("name");
                        String paymentId = "a98sjkhdjdu";//call.argument("paymentId");



                        String key ="*****";
                         String encryptionKey = "****";

                                new RavePayManager(activity).setAmount(Double.parseDouble(String.valueOf(amount)))
                                .setCountry(countryCode)
                                .setCurrency(currency)
                                .setEmail(email)
                                .setfName(name)
                                .setlName("")
                                .setNarration(narration)
                                .setPublicKey(key)
                                .setEncryptionKey(encryptionKey)
                                .setTxRef(paymentId)
                                .acceptMpesaPayments(false)
                                .acceptAccountPayments(true)
                                .acceptCardPayments(true)
                                .acceptGHMobileMoneyPayments(false)
                                .allowSaveCardFeature(true)
                                .onStagingEnv(false)
                                .initialize();
        } catch (IllegalViewOperationException e) {
            errorCallback.invoke(e.getMessage());
        }                  

    }

// React native code

   // async function to call the Java native method
    async sayHiFromJava() {
      HelloWorld.sayHi( (err) => {console.log(err)}, (msg) => {console.log(msg)} );
    }

Please help.


Viewing all articles
Browse latest Browse all 29448

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>