private void initDataProcessor() { DataProcessorConfiguration configuration = DataProcessorConfiguration .getBuilder() .setHost("google.com") .setLogEnabled(true) .setShowProcessingTime(true) .setTimeout(4000) .build(); DataProcessor.getInstance().init(configuration); }
Request request = GetRequest.newInstance() .setLogTag("FB Login to server") .addGetParam("signature", "DH$FHJDDBHJV3393n") .setPath("login.php") .build();
Request request = PostRequest.newInstance() .addPostParam("email", "some@gmail.com") .addPostParam("password", "any_password") .setLogTag("Login to server") .addGetParam(VAR_SIG, SIGNATURE) .setPath("auth2.php") .build();
Request request = MultipartRequest.newInstance() .addTextBody("userName", "Alex") .addTextBody("email", "some@gmail.com") .addTextBody("password", "any_password") .addTextBody("sex", "male") .addJPEG("imagedata", bitmap, "image.jpg") .setLogTag("Create user") .addGetParam(VAR_SIG, SIGNATURE) .setPath("createuser.php") .build();
public class LoginResult implements StringDataInterface { public static String token = ""; public static String email = ""; public static String password = ""; @Override public void fillFromString(String src) throws Exception { JSONObject jsonObject = new JSONObject(src); token = jsonObject.getString("token"); email = jsonObject.getString("email"); password = jsonObject.getString("password"); }
DataProcessor.getInstance().executeAsync(request, LoginResult.class, handler);
private DataProcessor.Callback callback = new DataProcessor.Callback() { @Override public void onFinish(Object obj, int what) { if (what == HttpStatus.SC_OK) { ... } else { Exception ex = (Exception) obj; if (ex instanceof IOException) { Log.e("IO Error", ex); } else { Log.e("Error", ex); } } } };
Source: https://habr.com/ru/post/227723/
All Articles