我使用facebook的图形api来安卓android。我无法从GraphRequest([...])中获取任何值.executeAsync()。所以返回字符串总是空的
private uploadPostImage(String imagePath) throws Exception {
String orientation = "Portrait";
Bitmap bm = null;
try {
bm = checkForRotation(imagePath);
if (bm.getHeight() > bm.getWidth()) {
orientation = "Portrait";
} else if (bm.getWidth() > bm.getHeight()) {
orientation = "Landscape";
} else {
orientation = "Portrait";
}
} catch (Exception e) {
Log.e(e.getClass().getName(), e.getMessage());
}
if(bm.getWidth()>1000)
{
bm = getResizedBitmap(bm,1000);
}
try {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.JPEG, 100, bos);
byte[] data = bos.toByteArray();
/*
/....
Multipart uploading work
..../
*/
} catch (Exception e) {
Log.e(e.getClass().getName(), e.getMessage());
}
}
public Bitmap checkForRotation(String filename) {
Bitmap bitmap = BitmapFactory.decodeFile(filename);
int tmpHeight, tmpWidth;
tmpWidth = bitmap.getWidth();
tmpHeight = bitmap.getHeight();
if (tmpWidth > tmpHeight)
{
tmpWidth = 1000;
tmpHeight = (bitmap.getHeight() * tmpWidth) / bitmap.getWidth();
} else
{
tmpHeight = 1000;
tmpWidth = (bitmap.getWidth() * tmpHeight) / bitmap.getHeight();
}
bitmap= Bitmap.createScaledBitmap(bitmap, tmpWidth, tmpHeight, true);
ExifInterface ei = null;
try {
ei = new ExifInterface(filename);
new ExifInterface(filename);
} catch (IOException e) {
e.printStackTrace();
}
int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION,
ExifInterface.ORIENTATION_NORMAL);
switch (orientation) {
case ExifInterface.ORIENTATION_ROTATE_90:
bitmap = rotateImage(bitmap, 90);
break;
case ExifInterface.ORIENTATION_ROTATE_180:
bitmap = rotateImage(bitmap, 180);
break;
}
return bitmap;
}
public Bitmap getResizedBitmap(Bitmap bm, int newWidth) {
int width = bm.getWidth();
int height = bm.getHeight();
float ratio = (float)width/(float)height;
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float)newWidth/ratio) / height;
// CREATE A MATRIX FOR THE MANIPULATION
Matrix matrix = new Matrix();
// RESIZE THE BIT MAP
matrix.postScale(scaleWidth, scaleHeight);
// RECREATE THE NEW BITMAP
Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height,
matrix, false);
return resizedBitmap;
}
答案 0 :(得分:0)
return friends
将返回默认friends
。你没有得到executeAsync()
的行为。 executeAsync()
将异步运行,方法将在安排executeAsync()
任务后立即返回。
数据friends
正在回调方法中进行修改,因此您必须从onCompleted()
返回。
要返回数据,您可以使用回调界面请参阅How to define callback。