Android:如何将facebook个人资料图片放入我的对话框中

时间:2012-12-07 14:17:35

标签: android facebook

我正在开发一个对话框。当我单击一个按钮时,它应该打开一个带有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 个答案:

答案 0 :(得分:1)

查看github上的官方Android Facebook SDK

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

答案 1 :(得分: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);

答案 2 :(得分: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);

答案 3 :(得分: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);