2014-10-17 75 views
0

我已經設法讓用戶將他們的圖片從他們的設備庫上傳到ima​​geview。但是,我試圖讓用戶能夠將他們的個人資料圖片從他們的臉書上傳到ima​​geview。將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()); 

標籤不能被解析爲一個變量

+0

您可以使用臉譜圖Api來解​​析用戶的個人資料圖片網址。檢查[這](http://stackoverflow.com/questions/6706977/how-to-get-the-facebook-profile-picture-in-my-android-application)可能會幫助你 – ashutiwari4 2014-10-17 05:17:51

回答

1

使用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()); 

            } 
           } 
          }); 
       } 

      } 
+0

感謝您的及時迴應。我在最初的帖子中添加了關於我的問題的更新。 – John 2014-10-17 05:58:36

+0

嘗試聲明您的profilePictureView外部onclick ..有一個FB登錄窗口小部件由FB sdk通過 LoginButton authButton =(LoginButton)findViewById(R.id.authButton); – Dhina 2014-10-17 06:02:01