detect为什么没有数据返回,直接跳到exception了
package aind.myapplication;
import android.graphics.Bitmap;
import android.util.Log;
import com.facepp.error.FaceppParseException;
import com.facepp.http.HttpRequests;
import com.facepp.http.PostParameters;
import org.json.JSONObject;
import java.io.ByteArrayOutputStream;
/**
* Created by Administrator on 2016/2/25.
* Request(发送请求)
*/
public class faceppDetect {
public interface CallBack {
void success(JSONObject result);
void error(FaceppParseException exception);
}
/**
*传入一张bitmap和callback接口
*/
public static void detect(final Bitmap bm, final CallBack callback) {
// 耗时操作
new Thread(new Runnable() {
@Override
public void run() {
try {
/***
* 将传入的bitmap转换为二进制数组,并通过PostParameters进行压缩
* 然后通过HttpRequests的detectionDetect()方法得到返回的JSONObject
*/
HttpRequests requests = new HttpRequests(constant.KEY,
constant.SECRET, true, true);
Bitmap bmSmall = Bitmap.createBitmap(bm, 0, 0,
bm.getWidth(), bm.getHeight());
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmSmall.compress(Bitmap.CompressFormat.JPEG, 100, stream);
byte[] arrays = stream.toByteArray();
PostParameters prameter = new PostParameters();
prameter.setImg(arrays);
JSONObject jsonObject = requests.detectionDetect();
//将JSONObject数据toString后打印日志
Log.e("TAG", jsonObject.toString());
if (callback != null) {
callback.success(jsonObject);
}
} catch (FaceppParseException e) {
e.printStackTrace();
if (callback != null) {
callback.error(e);
}
}
}
}).start();
}
}