我设法使用户将其图片从设备库上传到ima​​geview。但是,我试图为用户提供将其个人资料图片从其Facebook上传到ima​​geview的功能。

以下是我如何将图片从设备库上传到ima​​geview的方法,

 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
将其作为库添加到您的项目中
使用以下代码将获得用户的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());

                                    }
                                }
                            });
                }

            }

07-24 09:55