Open binhit92 opened 7 months ago
Sending Data Between Mini App and Super App You can send data from a mini app to a super app or vice versa using Send Events via Native Module.
iOS: It's easy to follow the instructions provided in the documentation.
Android: It's a bit more tricky.
a. Sending Events from Mini App to Super App: Follow the same instructions as for iOS, which can be found in the documentation.
b. Sending Events from Super App to Mini App: Create a BroadcastReceiver in the mini app activity (note that the super app is on the main activity). Listen for events sent by the super app. Receive the data and send it to the mini app bundle.
By following these steps, you can successfully send events between a mini app and a super app on both iOS and Android platforms.
private BroadcastReceiver myReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (BROASCAST_EVENT.equals(action)) {
Bundle bundle = intent.getBundleExtra("data");
String type = intent.getStringExtra("type");
WritableMap params = Arguments.createMap();
if (type != null && type.equals(DEEPLINK_EVENT_NAME)){
params.putString("deepLinkUrl", bundle.getString("deepLinkUrl"));
}
if (type != null && type.equals(PUSH_EVENT_NAME)){
params.putString("event", bundle.getString("event"));
params.putString("destination", bundle.getString("destination"));
params.putString("data", bundle.getString("data"));
}
sendEvent(type, params);
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
ReadySplash.show(this, true);// ⬅️ initialize the splash screen
super.onCreate(savedInstanceState);
mInstance = this;
Bundle bundle = getIntent().getExtras();
assert bundle != null;
Bundle initProps = bundle.getBundle("initProps");
mReactRootView = new ReactRootView(this);
mReactInstanceManager = ReactInstanceManager.builder()
.setApplication(getApplication())
.setJavaScriptExecutorFactory(new HermesExecutorFactory())
.setCurrentActivity(this)
.setBundleAssetName("ReadyWallet.bundle")
.setJSMainModulePath("index")
.addPackages(getPackages())
.setUseDeveloperSupport(false)
.setInitialLifecycleState(LifecycleState.RESUMED)
.build();
mReactRootView.startReactApplication(mReactInstanceManager, "ReadyWallet", initProps);
setContentView(mReactRootView);
// Register the receiver
registerReceiver(myReceiver, new IntentFilter(BROASCAST_EVENT));
isLaunch= true;
}
// Use the context to send events
private void sendEvent(String type, WritableMap params) {
mReactRootView.getReactInstanceManager().getCurrentReactContext().getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit(type, params);
}
How i can send data from mini app to super app? i was call sendMessage in native code but only recived in mini app.