以前我得到Facebook這樣的用戶個人資料圖片,一切都很好,直到最近。Facebook的個人資料圖片Android返回null
但現在每次都返回null。
這裏是網址:
"http://graph.facebook.com/"+userID+"/picture?height=100&type=normal&width=100"
會發生這種事,因爲從Facebook重定向的?因爲如果你在瀏覽器中打開這個URL,你會被重定向到這樣的:https://fbcdn-profile-a.akamaihd.net/......
。 有沒有辦法解決這個問題?
這裏是我的AsyncTask:
public class GetUserPicture extends AsyncTask<String, Void, Bitmap> {
ImageView profileImage;
public GetUserPicture(ImageView profileImage) {
this.profileImage = profileImage;
}
@Override
protected Bitmap doInBackground(String... urls) {
String urldisplay = urls[0];
Log.d("SHOW CORRECT URL", urldisplay);
Bitmap bitmap = null;
try {
URL url = new URL(urldisplay);
bitmap = BitmapFactory.decodeStream(url.openConnection().getInputStream());
HttpURLConnection.setFollowRedirects(true);
} catch (Exception e) {
e.printStackTrace();
}
return bitmap;
}
@Override
protected void onPostExecute(Bitmap result) {
if (result != null) {
Log.d("Not null", "NOT NULLL");
}
profileImage.setImageBitmap(getRoundedCornerBitmap(result, 70));
}
protected static Bitmap getRoundedCornerBitmap(Bitmap bitmap, int pixels) {
Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap
.getHeight(), Config.ARGB_8888);
BitmapShader bitmapShader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
Paint pnt = new Paint();
pnt.setAntiAlias(true);
pnt.setShader(bitmapShader);
Canvas canvas = new Canvas(output);
final int color = 0xff424242;
final Paint paint = new Paint();
final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
final RectF rectF = new RectF(rect);
final float roundPx = pixels;
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(color);
canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, rect, paint);
return output;
}
}
我得到這個畫面來自Facebook,使其圓,然後顯示它。但它過去兩週前工作正常!如果我通過重定向的url,看起來像這樣:https://fbcdn-profile-a.akamaihd.net/hprofile-ak-prn1/t1.0-1/c12.12.155.155/s100x100/....jpg
然後它顯示圖像!
以下是錯誤:
03-31 12:05:08.482: D/skia(14479): --- SkImageDecoder::Factory returned null
03-31 12:05:08.482: D/AndroidRuntime(14479): Shutting down VM
03-31 12:05:08.482: W/dalvikvm(14479): threadid=1: thread exiting with uncaught exception (group=0x41675d40)
03-31 12:05:08.484: E/AndroidRuntime(14479): FATAL EXCEPTION: main
03-31 12:05:08.484: E/AndroidRuntime(14479): Process: com.hitchhiker.mobile, PID: 14479
03-31 12:05:08.484: E/AndroidRuntime(14479): java.lang.NullPointerException
03-31 12:05:08.484: E/AndroidRuntime(14479): at com.hitchhiker.mobile.asynctasks.GetUserPicture.getRoundedCornerBitmap(GetUserPicture.java:54)
03-31 12:05:08.484: E/AndroidRuntime(14479): at com.hitchhiker.mobile.asynctasks.GetUserPicture.onPostExecute(GetUserPicture.java:50)
03-31 12:05:08.484: E/AndroidRuntime(14479): at com.hitchhiker.mobile.asynctasks.GetUserPicture.onPostExecute(GetUserPicture.java:1)
03-31 12:05:08.484: E/AndroidRuntime(14479): at android.os.AsyncTask.finish(AsyncTask.java:632)
03-31 12:05:08.484: E/AndroidRuntime(14479): at android.os.AsyncTask.access$600(AsyncTask.java:177)
03-31 12:05:08.484: E/AndroidRuntime(14479): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:645)
03-31 12:05:08.484: E/AndroidRuntime(14479): at android.os.Handler.dispatchMessage(Handler.java:102)
03-31 12:05:08.484: E/AndroidRuntime(14479): at android.os.Looper.loop(Looper.java:136)
03-31 12:05:08.484: E/AndroidRuntime(14479): at android.app.ActivityThread.main(ActivityThread.java:5102)
03-31 12:05:08.484: E/AndroidRuntime(14479): at java.lang.reflect.Method.invokeNative(Native Method)
03-31 12:05:08.484: E/AndroidRuntime(14479): at java.lang.reflect.Method.invoke(Method.java:515)
03-31 12:05:08.484: E/AndroidRuntime(14479): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
03-31 12:05:08.484: E/AndroidRuntime(14479): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
03-31 12:05:08.484: E/AndroidRuntime(14479): at dalvik.system.NativeStart.main(Native Method)
03-31 12:05:08.743: D/skia(14479): --- SkImageDecoder::Factory returned null
03-31 12:05:09.023: D/skia(14479): --- SkImageDecoder::Factory returned null
03-31 12:05:09.286: D/skia(14479): --- SkImageDecoder::Factory returned null
03-31 12:05:09.526: D/skia(14479): --- SkImageDecoder::Factory returned null
03-31 12:05:09.813: D/skia(14479): --- SkImageDecoder::Factory returned null
我在想這個解決方案,但我會提出2個請求!我只是不明白爲什麼這個'http://graph.facebook.com/「+ userID +」/ picture?height = 100&type = normal&width = 100'不起作用,但是這個'https:// fbcdn-profile-a .akamaihd.net/hprofile-ak-prn1/t5.0-1/23122_595273610_9552621_q.jpg'顯示圖片! – Karlis
你沒有得到任何錯誤/異常? –
我添加了異常 – Karlis