gpt4 book ai didi

java - 将 Facebook 图片上传到 imageview

转载 作者:行者123 更新时间:2023-12-01 12:25:10 25 4
gpt4 key购买 nike

我已经设法让用户将他们的图片从他们的设备图库上传到 ImageView 。然而,我试图为用户提供将他们的个人资料图片从他们的 Facebook 上传到 ImageView 的能力。

下面是我如何将图片从设备图库上传到 ImageView ,

 Button buttonLoadImage = (Button) findViewById(R.id.btnPictureSelect);
buttonLoadImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
Intent i = new Intent(
Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, RESULT_LOAD_IMAGE);
}
});

}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);

if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK
&& null != data) {
Uri selectedImage = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };

Cursor cursor = getContentResolver().query(selectedImage,
filePathColumn, null, null, null);
cursor.moveToFirst();

int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath = cursor.getString(columnIndex);
cursor.close();

ImageView imageView = (ImageView) findViewById(R.id.profilePicturePreview);
imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));

}

}

我正在尝试找出方法,以便当用户按下“btnFacebookUpload”按钮时,他们能够从 Facebook 画廊中选择一张图片,并将其转换到 ImageView “profilePicturePreview”

更新:

 Button buttonFacebookLoadImage = (Button) findViewById(R.id.btnFacebookUpload);
buttonFacebookLoadImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
ProfilePictureView profilePictureView;
profilePictureView = (ProfilePictureView) findViewById(R.id.profilePicturePreview);

buttonFacebookLoadImage.setSessionStatusCallback(new Session.StatusCallback() {

@SuppressWarnings("deprecation")
@Override
public void call(Session session, SessionState state,
Exception exception) {
Log.i(TAG, "Access Token" + session.getAccessToken());
Request.executeMeRequestAsync(session,
new Request.GraphUserCallback() {
@Override
public void onCompleted(GraphUser user,
Response response) {
if (user != null) {
profilePictureView.setProfileId(user.getId());

}
}
});
}



});

问题:无法引用在不同方法中定义的内部类内的非最终变量buttonFacebookLoadImage

排队

buttonFacebookLoadImage.setSessionStatusCallback(new Session.StatusCallback() {

还有

无法引用不同方法中定义的内部类中的非最终变量 profilePictureView

排队

        profilePictureView.setProfileId(user.getId());

TAG 无法解析为变量

最佳答案

使用FB SDK You can download from here将其作为库添加到 ypur 项目

使用以下代码即可获取用户的FB头像

ProfilePictureView profilePictureView;
profilePictureView = (ProfilePictureView) findViewById(R.id.imageView);

authButton.setSessionStatusCallback(new Session.StatusCallback() {

@SuppressWarnings("deprecation")
@Override
public void call(Session session, SessionState state,
Exception exception) {
Log.i(TAG, "Access Token" + session.getAccessToken());
Request.executeMeRequestAsync(session,
new Request.GraphUserCallback() {
@Override
public void onCompleted(GraphUser user,
Response response) {
if (user != null) {
profilePictureView.setProfileId(user.getId());

}
}
});
}

}

关于java - 将 Facebook 图片上传到 imageview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26417850/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com