我已經設法讓用戶將他們的圖片從他們的設備庫上傳到imageview。但是,我試圖讓用戶能夠將他們的個人資料圖片從他們的臉書上傳到imageview。將facebook圖片上傳到圖像查看
下面是我得到了從設備畫廊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());
標籤不能被解析爲一個變量
您可以使用臉譜圖Api來解析用戶的個人資料圖片網址。檢查[這](http://stackoverflow.com/questions/6706977/how-to-get-the-facebook-profile-picture-in-my-android-application)可能會幫助你 – ashutiwari4 2014-10-17 05:17:51