URL1:从 facebook 获取图像的 URL:http://graph.facebook.com/ {fb-user-id}/picture?type=large
URL2:当 URL1 被点击时 Facebook 重定向的 URL https://fbcdn-profile-a.akamaihd.net/hprofile-ak-prn1/t5.0-1/371818_100002856860463_136071413_n.jpg
Facebook 个人资料图像未显示在 ImageView Android 中。这可能是因为从 facebook 获取图像的 url(即 URL1)重定向到其他位置以提供图像。当我使用重定向的 url(即 URL2)直接加载图像时,它工作正常。
获取位图的代码:
Bitmap b = null;
URL url = null;
try {
url = new URL(image_path);
URLConnection dd = url.openConnection();
b = BitmapFactory.decodeStream(dd.getInputStream());
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
我已经用谷歌搜索了很多,并且在 stackoverflow 本身上得到了一些答案(并且可能是重复的),但没有得到任何可以解决这个问题的答案。提前致谢。
最佳答案
您可以通过使用 facebook ProfilePictureView 而不是 Imageview 来实现它
<com.facebook.login.widget.ProfilePictureView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
facebook:preset_size="small"/>
之后你可以在代码中像这样设置facebook id
ProfilePictureView profilePictureView;
profilePictureView = (ProfilePictureView)findViewById(R.id.friendProfilePicture);
profilePictureView.setProfileId(userId);
它有效..
您还可以将 ProfilePictureView 的尺寸设置为小/正常/大/自定义
关于java - Facebook 个人资料图像未显示在 Android ImageView 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23006048/