I successfully created a custom react native module that allows me to open another app and launch an intent for it. I can’t seem to get the response back onto react native when the opened app finishes what it was doing. I’ve tried using .startActivityForResult() but I run into some issues since my MainActivity is extending the DevMenuAwareActivity and asks for an extra parameter that I can’t seem to get.
I was following this exact thread: Link but ran into the issue when trying to populate the mReactInstanceManager.onActivityResult method.
My MainActivity:
private ReactInstanceManager mReactInstanceManager;
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
mReactInstanceManager.onActivityResult(this, requestCode, resultCode, data);
}
public class PaymentModule extends ReactContextBaseJavaModule implements ActivityEventListener {
private final ReactApplicationContext reactContext;
Promise promise;
public PaymentModule(ReactApplicationContext reactContext) {
super(reactContext);
this.reactContext = reactContext;
this.reactContext.addActivityEventListener(this);
}
@Override
public String getName() {
return "PaymentModule";
}
@ReactMethod
public void openExampleApp(String amount, String messageType, String currencyCode, String currencyFraction, String currencyAlpha, String transactionId){
try {
Log.d("PaymentModule", "Trigger openPaxPayment Fn: "+amount);
this.promise = promise;
Intent paymentIntent = new Intent("com.my.example.REQUEST");
paymentIntent.putExtra("MESSAGE_TYPE", messageType);
paymentIntent.putExtra("AMOUNT", amount);
paymentIntent.putExtra("CURRENCY_CODE", currencyCode);
paymentIntent.putExtra("CURRENCY_FRACTION", currencyFraction);
paymentIntent.putExtra("CURRENCY_ALPHA", currencyAlpha);
paymentIntent.putExtra("MERCHANT_TRS_ID", transactionId);
Bundle dataBundle = paymentIntent.getExtras();
getReactApplicationContext().startActivityForResult(paymentIntent, 8888,dataBundle);
} catch (Exception e) {
Log.d("PaymentModule Err", String.valueOf(e));
e.printStackTrace();
}
}
@Override
public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent data) {
this.promise.resolve(data.getDataString());
}
@Override
public void onNewIntent(Intent intent) {
}
}
I can’t seem to find concrete or clear information on the ActivityEventListener implementation when on bare workflow.
Any tips?