Kaynağa Gözat

Pass deep link to NavigationActivity

This commit introduces a simple mechanism to pass deep link data from
MainActivity/SplashActivity to NavigationActivity. Note that this will
not work if the application is already running.
Guy Carmeli 8 yıl önce
ebeveyn
işleme
89770b923b

+ 26
- 0
android/app/src/main/java/com/reactnativenavigation/controllers/Linking.java Dosyayı Görüntüle

@@ -0,0 +1,26 @@
1
+package com.reactnativenavigation.controllers;
2
+
3
+import android.content.Intent;
4
+import android.net.Uri;
5
+
6
+import static android.content.Intent.ACTION_VIEW;
7
+
8
+public class Linking {
9
+    private static Uri initialUri;
10
+
11
+    static void saveInitialUri(Uri initialUri) {
12
+        Linking.initialUri = initialUri;
13
+    }
14
+
15
+    static void setInitialUri(Intent intent) {
16
+        if (initialUri != null) {
17
+            intent.setData(initialUri);
18
+            intent.setAction(ACTION_VIEW);
19
+            clear();
20
+        }
21
+    }
22
+
23
+    private static void clear() {
24
+        initialUri = null;
25
+    }
26
+}

+ 1
- 0
android/app/src/main/java/com/reactnativenavigation/controllers/NavigationCommandsHandler.java Dosyayı Görüntüle

@@ -36,6 +36,7 @@ public class NavigationCommandsHandler {
36 36
         } else {
37 37
             intent = new Intent(NavigationApplication.instance, NavigationActivity.class);
38 38
         }
39
+        Linking.setInitialUri(intent);
39 40
         intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
40 41
         intent.putExtra(ACTIVITY_PARAMS_BUNDLE, params);
41 42
         NavigationApplication.instance.startActivity(intent);

+ 1
- 0
android/app/src/main/java/com/reactnativenavigation/controllers/SplashActivity.java Dosyayı Görüntüle

@@ -16,6 +16,7 @@ public abstract class SplashActivity extends AppCompatActivity {
16 16
     protected void onCreate(@Nullable Bundle savedInstanceState) {
17 17
         super.onCreate(savedInstanceState);
18 18
         setSplashLayout();
19
+        Linking.saveInitialUri(getIntent().getData());
19 20
     }
20 21
 
21 22
     @Override