當我做一個個人資料圖片的請求,在這種情況下,我在我的HttpResponseHandler中收到某種編碼的字符串。下面的代碼是對我的個人資料圖片的請求。Facebook的個人資料圖片請求,即「http://graph.facebook.com/me/picture」
private static AsyncHttpClient client = new AsyncHttpClient();
client.get("http://graph.facebook.com/1206433/picture", fbPictureHandler);
下面的代碼是我的處理程序來檢索響應。我以字符串的形式得到響應,但我不確定如何處理這個響應對象。我試圖轉換爲一個字節數組,並寫入「file.jpg」這沒有奏效。我的主要問題是我該如何處理這個響應對象?
private static AsyncHttpResponseHandler fbPictureHandler = new AsyncHttpResponseHandler()
{
@Override
public void onStart() {
Log.d(TAG,"started picture handler");
}
@Override
public void onSuccess(String response) {
//Not sure what to do here, have been unable to do anything with this Byte //array
byte[] imageBackground = response.getBytes();
}
@Override
public void onFailure(Throwable error) {
Log.d(TAG, "unable to retrieve picture");
error.printStackTrace();
}
@Override
public void onFinish() {
Log.d(TAG,"Finished picture handler");
}
};
這是響應對象
11-29 19:42:12.640: D/Yatter Facebook(3551): ÿØÿà��JFIF������������ÿþ��;CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), quality = 95
任何幫助的PRINTSTRING是極大的讚賞,希望這可以幫助其他人。
謝謝
大這實際上幫助,現在我知道如何使用帶有圖片字段的JSONObject來獲取實際的重定向URL。只是爲了讓你知道,雖然我用這個代碼來檢索位圖'位= BitmapFactory.decodeStream((InputStream的)新的URL( \t \t \t \t \t \t「http://graph.facebook.com/"+facebookId+」/picture?type = medium「)。getContent());' – Danuofr
順便說一下,我使用AsyncTask來檢索每個圖像,非常感謝Robin。 – Danuofr