From 548cc651dd02c4497144a753159c8501dbdb822e Mon Sep 17 00:00:00 2001 From: Alex Austin Date: Tue, 28 Jun 2016 10:04:05 -0700 Subject: [PATCH] Fix Android NonBranchLinkHandler --- src/android/io/branch/BranchSDK.java | 33 ++++++++++++++++------------ 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/src/android/io/branch/BranchSDK.java b/src/android/io/branch/BranchSDK.java index 2df86e60..18e0db3b 100644 --- a/src/android/io/branch/BranchSDK.java +++ b/src/android/io/branch/BranchSDK.java @@ -701,34 +701,39 @@ public void onInitFinished(JSONObject referringParams, BranchError error) { String out; - if (error == null) { + if (error == null && referringParams != null) { // params are the deep linked params associated with the link that the user clicked -> was re-directed to this app // params will be empty if no data found. - if (referringParams != null) { - - out = String.format("DeepLinkHandler(%s)", referringParams.toString()); - - webView.sendJavascript(out); - + try { + if (referringParams.has("+clicked_branch_link") && referringParams.getBoolean("+clicked_branch_link")) { + out = String.format("DeepLinkHandler(%s)", referringParams.toString()); + webView.sendJavascript(out); + } else if (deepLinkUrl != null) { + JSONObject message = new JSONObject(); + + message.put("error", "Not a Branch link!"); + message.put("url", deepLinkUrl); + deepLinkUrl = null; + + out = String.format("NonBranchLinkHandler(\"%s\")", message.toString()); + webView.sendJavascript(out); + } + } catch (JSONException e) { + e.printStackTrace(); } if (this._callbackContext != null) { this._callbackContext.success(referringParams); } - } else if (deepLinkUrl != null) { + } else { JSONObject message = new JSONObject(); try { - message.put("error", "Not a Branch link!"); - message.put("url", deepLinkUrl); - deepLinkUrl = null; + message.put("error", error.getMessage()); } catch (JSONException e) { e.printStackTrace(); } - - out = String.format("NonBranchLinkHandler(\"%s\")", message.toString()); - webView.sendJavascript(out); if (this._callbackContext != null) { this._callbackContext.error(message);