Skip to content

Instantly share code, notes, and snippets.

@netdur
Last active August 22, 2017 01:55
Show Gist options
  • Save netdur/d8038250bb29f580aa25fb9466925ec1 to your computer and use it in GitHub Desktop.
Save netdur/d8038250bb29f580aa25fb9466925ec1 to your computer and use it in GitHub Desktop.
android enroll
// bitmap is a photo take from camera, assets or gallery,
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 92, byteArrayOutputStream);
byte[] byteArray = byteArrayOutputStream.toByteArray();
String b64 = Base64.encodeToString(byteArray, Base64.DEFAULT);
JSONObject json = new JSONObject();
try {
json.put("img0", b64);
// repeat as necessary, at least 5
} catch (JSONException e) {
Log.d("JSONException", e.getMessage());
}
Map<String, String> headers = new HashMap<String, String>();
headers.put("x-api-key", "YOUR_API_KEY_HERE");
headers.put("Content-Type", "application/json");
Fuel.post("https://api.chui.ai/v1/enroll")
.header(headers)
.body(json.toString(), Charset.forName("UTF-8"))
.responseString(new com.github.kittinunf.fuel.core.Handler<String>() {
@Override
public void failure(@NotNull com.github.kittinunf.fuel.core.Request request,
@NotNull com.github.kittinunf.fuel.core.Response response,
@NotNull FuelError error) {
Log.d("Fuel.failure", error.getMessage());
}
@Override
public void success(@NotNull com.github.kittinunf.fuel.core.Request request,
@NotNull com.github.kittinunf.fuel.core.Response response,
String data) {
// data is a string, parse as using you fav json library
Log.d("Fuel.success", data);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment