Skip to content

Commit

Permalink
fix: removed csp violation (#381)
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanneff committed Oct 17, 2017
1 parent 4982186 commit 75ef406
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/android/io/branch/BranchSDK.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.annotation.TargetApi;
import android.net.Uri;
import android.os.Build;

import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;
Expand All @@ -15,8 +18,6 @@
import java.util.ArrayList;
import java.util.Iterator;

import android.net.Uri;

import io.branch.indexing.BranchUniversalObject;
import io.branch.referral.Branch;
import io.branch.referral.BranchError;
Expand Down Expand Up @@ -74,6 +75,23 @@ public void onNewIntent(Intent intent) {

}

/**
* Handle depreciated call to sendJavaScript for more recent method
*/
@TargetApi(Build.VERSION_CODES.KITKAT)
private void sendJavascript(final String javascript) {
webView.getView().post(new Runnable() {
@Override
public void run() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
webView.sendJavascript(javascript);
} else {
webView.loadUrl("javascript:" + javascript);
}
}
});
}

/**
* <p>
* cordova.exec() method reference.
Expand Down Expand Up @@ -808,7 +826,7 @@ public void onInitFinished(JSONObject referringParams, BranchError error) {
if (error == null && referringParams != null) {

out = String.format("DeepLinkHandler(%s)", referringParams.toString());
webView.sendJavascript(out);
sendJavascript(out);

if (this._callbackContext != null) {
this._callbackContext.success(referringParams);
Expand Down

0 comments on commit 75ef406

Please sign in to comment.