0

我正在处理一个对话框。当我单击一个按钮时,它应该会打开一个带有 Facebook 个人资料图像的对话框。我怎样才能做到这一点?下面是我的对话框。

final Dialog dialog = new Dialog(context);
                        dialog.setContentView(R.layout.customdailog);



                        ImageView image = (ImageView) dialog.findViewById(R.id.imageView2);
                        image.setImageResource(R.drawable.fb);

                        Button dialogButton = (Button) dialog.findViewById(R.id.fbshare);

                        dialogButton.setOnClickListener(new OnClickListener() {

                            public void onClick(View v) {
                                dialog.dismiss();
                        }

                        });
                        dialog.show();
                        break;
                    }
4

4 回答 4

1

做这个:

ImageView image = (ImageView) dialog.findViewById(R.id.imageView2);
URL url = new URL("https://www.graph.facebook.com/jesselchen/picture");
Bitmap pic = BitmapFactory.decodeStream(url.openConnection().getInputStream());
image.setImageBitmap(pic);
于 2012-12-07T22:20:24.133 回答
1

graphAPI 不需要授权即可获取个人资料图片等公共数据。

像这样构造一个 URL:

String userID = "TheNameOrIDOfTheUserYouWant";
String urlConstruct = "https://www.graph.facebook.com/" + userID + "/picture";
URL url = new URL(urlConstruct);

然后只需抓取数据并将图像加载到 ImageView 中。

ImageView profilePic = (ImageView) dialog.findViewById(R.id.profile_pic);
Bitmap imageFromURL = BitmapFactory.decodeStream(url.openConnection().getInputStream());
profilePic.setImageBitmap(imageFromURL);
于 2013-12-03T13:16:25.063 回答
1

在 github上查看官方的Android Facebook SDK

用户个人资料图片也是公开的,这意味着不需要授权,您只需加载用户页面 URL,解析响应正文并获取图像

于 2012-12-07T14:20:51.993 回答
0

用这个:

ImageView image = (ImageView) dialog.findViewById(R.id.imageView1);  
URL url = new URL("https://graph.facebook.com/"+fb_user_id+"/picture?type=large");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();  
HttpURLConnection.setFollowRedirects(true);
conn.setInstanceFollowRedirects(true);  
Bitmap fbpicture = BitmapFactory.decodeStream(conn.getInputStream());
image.setImageBitmap(fbpicture);
于 2014-11-17T07:12:02.943 回答