Hey guys,
I'm having some issues to use the plugin with react-native-navigation on Android (IOS works well).
I followed the instructions but I can't get the event from the subscribe method.
Any idea if the plugin should work with react-native-navigation ?
Here is my code:
AndroidManifest.xml
<application
android:name=".MainApplication"
android:allowBackup="true"
android:launchMode="singleTop"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
<intent-filter>
<data android:scheme="craver" android:host="open" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
<receiver android:name="io.branch.referral.InstallListener" android:exported="true">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
<meta-data android:name="io.branch.sdk.BranchKey" android:value="key_test_xxx"/>
....
MainApplication.java
public class MainApplication extends NavigationApplication {
private Activity activityInstance;
@Override
public void onCreate() {
super.onCreate();
setActivityCallbacks(new ActivityCallbacks() {
@Override
public void onActivityStarted(Activity activity) {
Log.d("MyApp", "onActivityStarted");
activityInstance = activity;
RNBranchModule.initSession(activity.getIntent().getData(), activity);
}
@Override
public void onNewIntent(Intent intent) {
Log.d("MyApp", "onNewIntent");
activityInstance.setIntent(intent);
}
});
// Init Branch
Branch.getAutoInstance(this);
}
....
}
RESULTS:
1/ When I'm clicking the link, It's opening the app but I have no params, I'm getting:
2/ onNewIntent is never called (it has been implemented in [email protected], should work)
Do you think it may be related to onNewIntent not being called ?
Would appreciate your help, would be nice to finally being able to use Branch.
Thanks
Hi @maxs15. Thanks for the bug report. I wasn't familiar with react-native-navigation. It may be that there are some issues, though I need to dig a bit. Here is something that might explain what you're seeing. ("Once react is up and running MainActivity is stopped and another activity takes over to run our app: NavigationActivity.")
The intent-filter that you have in your manifest is within the MainActivity declaration. There is no reason to think that onNewIntent would be called on the NavigationActivity or any activities it manages given that manifest. It may be that you get the URI back at launch because the MainActivity is still alive. I'm not sure why you would get null for params however.
Probably the reason that it works on iOS is that link handling occurs at the application level, through a method on the AppDelegate. It isn't bound to a specific view controller or other view context. On Android link handling is usually done at the activity level.
Perhaps you could add the same intent-filter with your URI scheme for the NavigationActivity and see if onNewIntent fires. I'll keep looking to see what else might be going on.
Thanks for the help @jdee,
That's what I was thinking about too (even though my knowledge on Android are limited).
I asked the guy taking care of the plugin and he told me that intent filters in MainActivity should work since it extends SplashActivity which passes the data from the original intent to NavigationActivity.
cf: https://github.com/wix/react-native-navigation/issues/384#issuecomment-279466848
I'm closing the issue, @guyca just pushed a fix for the intents to work properly.
It landed in [email protected], and the linking is now working like a charm !
Thanks for looking at the issue @jdee
Hi,
I can't use this with react-native-navigation as well and unfortunately I cannot upgrade to RNN 2. @jdee any chance you can confirm that react-native-branch should work fine with RNN? If so, would appreciate being pointed in the right direction (My Android knowledge is limited).
@harrisrobin Have you found any solution?
@perrosnk
I moved to react-navigation
@maxs15 Could you please share your working MainApplication.java file?
Most helpful comment
I'm closing the issue, @guyca just pushed a fix for the intents to work properly.
It landed in [email protected], and the linking is now working like a charm !
Thanks for looking at the issue @jdee