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