Created
April 23, 2020 16:05
-
-
Save felansu/c90c8d7c3dd1c6a194b7c816f88bcdd8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package br.com.cloq.combateAFraude; | |
import android.content.Context; | |
import android.content.Intent; | |
import android.os.Bundle; | |
import com.combateafraude.helpers.sdk.FaceLivenessMode; | |
import com.combateafraude.onboarding.Onboarding; | |
import com.combateafraude.onboarding.OnboardingResult; | |
import com.facebook.react.bridge.Callback; | |
import com.facebook.react.bridge.ReactApplicationContext; | |
import com.facebook.react.bridge.ReactContextBaseJavaModule; | |
import com.facebook.react.bridge.ReactMethod; | |
import org.jetbrains.annotations.NotNull; | |
import org.jetbrains.annotations.Nullable; | |
public class CombateAFraudeModule extends ReactContextBaseJavaModule { | |
private Context ctx; | |
private static final int REQUEST_CODE = 50000; | |
public CombateAFraudeModule(ReactApplicationContext reactContext) { | |
super(reactContext); | |
this.ctx = reactContext.getApplicationContext(); | |
} | |
@NotNull | |
@Override | |
public String getName() { | |
return "CombateAFraude"; | |
} | |
@ReactMethod | |
public void onboarding(String cpf, String report, Callback cb) { | |
try { | |
Onboarding onboarding = new Onboarding.Builder("CAF_API_TOKEN", "MOBILE_TOKEN") | |
.setCpf(cpf) | |
.setReportId(report) //required | |
.setFaceLivenessMode(FaceLivenessMode.MOTION) //required. Can be FaceLivenessMode.MOTION or FaceLivenessMode.EFFORTLESS | |
.build(); | |
Intent intent = new Intent("com.combateafraude.onboarding.OnboardingActivity"); | |
intent.putExtra(Onboarding.PARAMETER_NAME, onboarding); | |
getReactApplicationContext().startActivityForResult(intent, REQUEST_CODE, Bundle.EMPTY); | |
cb.invoke(true); | |
} catch (Exception e) { | |
cb.invoke(false); | |
} | |
} | |
@Override | |
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { | |
if (requestCode == REQUEST_CODE) { | |
if (resultCode == 200 && data != null) { | |
OnboardingResult mOnboardingResult = (OnboardingResult) data.getSerializableExtra(OnboardingResult.PARAMETER_NAME); | |
System.out.println(mOnboardingResult.getSdkFailure()); | |
System.out.println(mOnboardingResult); | |
// check the mOnboardingResult.getSDKFailure() here to know for which reason the SDK had finished. | |
} else { | |
// the user closed the activity | |
} | |
} | |
super.onActivityResult(requestCode, resultCode, data); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment