Skip to content

Commit

Permalink
Used IBranchLoggingCallbacks to retrieve the Branch logs
Browse files Browse the repository at this point in the history
Used IBranchLoggingCallbacks to retrieve the Branch logs
  • Loading branch information
rob-gioia-branch committed Oct 25, 2024
1 parent 2cf8f00 commit effe1d5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@

import java.util.Objects;

import io.branch.interfaces.IBranchLoggingCallbacks;
import io.branch.referral.Branch;

public class IntegrationValidator implements ServerRequestGetAppConfig.IGetAppConfigEvents {

private static IntegrationValidator instance;
private final BranchIntegrationModel integrationModel;
private final String TAG = "BranchSDK_Doctor";
private final StringBuilder branchLogsStringBuilder;

Context context;

Expand All @@ -26,16 +28,30 @@ public class IntegrationValidator implements ServerRequestGetAppConfig.IGetAppCo
private IntegrationValidator(Context context) {
this.integrationModel = new BranchIntegrationModel(context);
this.context = context;
this.branchLogsStringBuilder = new StringBuilder();
}

public static void validate(Context context) {
if (instance == null) {
instance = new IntegrationValidator(context);
}

IBranchLoggingCallbacks iBranchLoggingCallbacks = new IBranchLoggingCallbacks() {
@Override
public void onBranchLog(String logMessage, String severityConstantName) {
instance.branchLogsStringBuilder.append(logMessage);
}
};

Branch.enableLogging(iBranchLoggingCallbacks);
instance.validateSDKIntegration(context);
instance.integrationValidatorDialog = new IntegrationValidatorDialog(context);
}

public static String getLogs() {
return instance.branchLogsStringBuilder.toString();
}

private void validateSDKIntegration(Context context) {
Branch.getInstance().requestQueue_.handleNewRequest(new ServerRequestGetAppConfig(context, IntegrationValidator.this));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
import android.widget.Button;
import android.widget.TextView;

import java.io.BufferedReader;
import java.io.InputStreamReader;

import io.branch.referral.Branch;
import io.branch.referral.R;

Expand Down Expand Up @@ -86,24 +83,11 @@ private void setResult(IntegrationValidatorDialogRowItem rowItem, String name, b
}

private void shareLogsAsText(Context context) {
try {
Process process = Runtime.getRuntime().exec("logcat -d BranchSDK:V *:S");
BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader(process.getInputStream()));

StringBuilder log=new StringBuilder();
String line = "";
while ((line = bufferedReader.readLine()) != null) {
log.append(line + "\n");
}
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, new String(log));
sendIntent.putExtra(Intent.EXTRA_TEXT, IntegrationValidator.getLogs());
sendIntent.setType("text/plain");
Intent shareIntent = Intent.createChooser(sendIntent, null);
context.startActivity(shareIntent);
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
}

0 comments on commit effe1d5

Please sign in to comment.