Skip to content

Commit 6d7c702

Browse files
committed
Added basic android side
1 parent 304ecd0 commit 6d7c702

File tree

2 files changed

+74
-15
lines changed

2 files changed

+74
-15
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/src/android" isTestSource="false" />
7+
</content>
8+
<orderEntry type="inheritedJdk" />
9+
<orderEntry type="sourceFolder" forTests="false" />
10+
</component>
11+
</module>

src/android/io/branch/BranchSDK.java

Lines changed: 63 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import android.net.Uri;
77
import android.os.Build;
88
import android.util.Log;
9+
import android.util.Base64;
910

1011
import org.apache.cordova.CallbackContext;
1112
import org.apache.cordova.CordovaPlugin;
@@ -16,6 +17,7 @@
1617

1718
import java.util.ArrayList;
1819
import java.util.Iterator;
20+
import java.io.IOException;
1921

2022
import io.branch.indexing.BranchUniversalObject;
2123
import io.branch.referral.Branch;
@@ -24,13 +26,15 @@
2426
import io.branch.referral.ServerRequestGetCPID.BranchCrossPlatformIdListener;
2527
import io.branch.referral.ServerRequestGetLATD.BranchLastAttributedTouchDataListener;
2628
import io.branch.referral.SharingHelper;
29+
import io.branch.referral.QRCode.BranchQRCode;
2730
import io.branch.referral.util.BRANCH_STANDARD_EVENT;
2831
import io.branch.referral.util.BranchCPID;
2932
import io.branch.referral.util.BranchEvent;
3033
import io.branch.referral.util.ContentMetadata;
3134
import io.branch.referral.util.CurrencyType;
3235
import io.branch.referral.util.ShareSheetStyle;
3336

37+
3438
public class BranchSDK extends CordovaPlugin {
3539

3640
static class BranchLinkProperties extends io.branch.referral.util.LinkProperties {
@@ -526,26 +530,36 @@ private void getBranchQRCode(JSONObject qrCodeSettings, int instanceIdx, JSONObj
526530
BranchUniversalObjectWrapper branchUniversalWrapper = (BranchUniversalObjectWrapper) this.branchObjectWrappers.get(instanceIdx);
527531
BranchUniversalObject buo = branchUniversalWrapper.branchUniversalObj;
528532

533+
BranchQRCode qrCode = new BranchQRCode();
534+
//setCodeColor, setWidth, etc.
535+
529536
try {
530-
qrCode.getQRCodeAsData(getReactApplicationContext().getCurrentActivity(), branchUniversalObject, linkProperties, new BranchQRCode.BranchQRCodeDataHandler() {
531-
@Override
532-
public void onSuccess(byte[] qrCodeData) {
533-
String qrCodeString = Base64.encodeToString(qrCodeData, Base64.DEFAULT);
534-
promise.resolve(qrCodeString);
535-
}
536-
537-
@Override
538-
public void onFailure(Exception e) {
539-
Log.d("Failed to get QR Code", e.getMessage());
540-
promise.reject("Failed to get QR Code", e.getMessage());
541-
}
542-
});
537+
qrCode.getQRCodeAsData(this.activity, buo, linkProperties, new GetBranchQRCodeListener(callbackContext));
543538
} catch (IOException e) {
544539
e.printStackTrace();
545540
Log.d("Failed to get QR Code", e.getMessage());
546-
promise.reject("Failed to get QR Code", e.getMessage());
547541
}
548-
542+
543+
//try {
544+
// qrCode.getQRCodeAsData(this.activity, branchUniversalObject, linkProperties, new GetBranchQRCodeListener(callbackContext)) {
545+
// @Override
546+
// public void onSuccess(byte[] qrCodeData) {
547+
// String qrCodeString = Base64.encodeToString(qrCodeData, Base64.DEFAULT);
548+
// promise.resolve(qrCodeString);
549+
// }
550+
551+
// @Override
552+
// public void onFailure(Exception e) {
553+
// Log.d("Failed to get QR Code", e.getMessage());
554+
// promise.reject("Failed to get QR Code", e.getMessage());
555+
// }
556+
// });
557+
// } catch (IOException e) {
558+
// e.printStackTrace();
559+
// Log.d("Failed to get QR Code", e.getMessage());
560+
// promise.reject("Failed to get QR Code", e.getMessage());
561+
// }
562+
549563
//branchUniversalWrapper.branchUniversalObj.generateShortUrl(this.activity, linkProperties, new GenerateShortUrlListener(callbackContext));
550564

551565
}
@@ -1060,6 +1074,38 @@ public void onLinkCreate(String url, BranchError error) {
10601074

10611075
}
10621076

1077+
protected class GetBranchQRCodeListener implements BranchQRCode.BranchQRCodeDataHandler {
1078+
private CallbackContext _callbackContext;
1079+
1080+
// Constructor that takes in a required callbackContext object
1081+
public GetBranchQRCodeListener(CallbackContext callbackContext) {
1082+
1083+
this._callbackContext = callbackContext;
1084+
1085+
}
1086+
1087+
@Override
1088+
public void onSuccess(byte[] qrCodeData) {
1089+
1090+
String qrCodeString = Base64.encodeToString(qrCodeData, Base64.DEFAULT);
1091+
1092+
String response = qrCodeString;
1093+
1094+
Log.d(LCAT, response);
1095+
this._callbackContext.success(response);
1096+
}
1097+
1098+
@Override
1099+
public void onFailure(Exception e) {
1100+
1101+
String errorMessage = String.valueOf(e);
1102+
1103+
Log.d(LCAT, errorMessage);
1104+
this._callbackContext.error(errorMessage);
1105+
}
1106+
1107+
}
1108+
10631109
protected class ShowShareSheetListener implements Branch.BranchLinkShareListener {
10641110

10651111
private CallbackContext _onShareLinkDialogLaunched;
@@ -1239,6 +1285,8 @@ public void run() {
12391285
lastAttributedTouchData(this.callbackContext);
12401286
} else if (this.action.equals(("generateShortUrl"))) {
12411287
generateShortUrl(this.args.getInt(0), this.args.getJSONObject(1), this.args.getJSONObject(2), this.callbackContext);
1288+
} else if (this.action.equals(("getBranchQRCode"))) {
1289+
getBranchQRCode(this.args.getJSONObject(0), this.args.getInt(1), this.args.getJSONObject(2), this.args.getJSONObject(3), this.callbackContext);
12421290
} else if (this.action.equals("registerView")) {
12431291
registerView(this.args.getInt(0), this.callbackContext);
12441292
} else if (this.action.equals("showShareSheet")) {

0 commit comments

Comments
 (0)