1

I am trying to set up android app link for my app. The problem is that the intent is received by an activity and I need to send this event to my javascript code(to navigate to the correct screen) through RCTDeviceEventEmitter but for this to happen I need to get react context somehow in my activity's code...I have no idea how to do this..This is what I have tried:

public class NewFriendActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(null);
    class ReactContextFetcher extends ReactContextBaseJavaModule {
        @Override
        public String getName() {
            return "ReactContextFetcher";
        }

        public ReactContext fetchReactContext() {
            return getReactApplicationContext();
        }

    }
    Intent intent = getIntent();
    String data = intent.getData().toString();
    String user = data.split("/add-friend/")[1];
    Log.d("obscure_tag", user);
    ReactContext rContext = new ReactContextFetcher().fetchReactContext();
    Log.d("obscure_tag", "this is run as well..");
    sendEvent(rContext, "NewFriend", user);
}

private void sendEvent(ReactContext reactContext,
                       String eventName, String user) {
    reactContext
            .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
            .emit(eventName, user);
}
}

"user" gets logged but "this is run as well.." doesn't, the app crashes before that..So I get that fetchReactContext() is not the correct way to get react context..I referred to this but actually I did not understand what that guy is trying to say..How should I get react context in this situation?

Pro
  • 445
  • 4
  • 14
  • Please use firebase SDK see this link: https://rnfirebase.io/dynamic-links/usage.you don't need to build something others built already – Hamza Hmem Sep 19 '22 at 10:27

0 Answers0