Android:在ImageView上显示Facebook个人资料图片

时间:2015-03-19 17:31:53

标签: android facebook image imageview

我目前正在开发一个连接到Facebook的应用程序。只有我有问题,我想显示同意ImageView的人的个人资料图片...有谁知道如何在ImageView中显示个人资料图片?

我有以下代码:

public class Profile_Facebook扩展Activity {     私人UiLifecycleHelper uihelper;

void showMsg(String string)
   {
       Toast.makeText(getApplicationContext(), string, Toast.LENGTH_SHORT).show();
   }

ImageView image_profile;

@Override
protected void onCreate(Bundle savedInstanceState){

    super.onCreate(savedInstanceState);
    setContentView(R.layout.profile_facebook);
    uihelper =new UiLifecycleHelper(this,callback);  
    uihelper.onCreate(savedInstanceState);

    ArrayList<String> permission =new ArrayList<String>();
    permission.add("email");
    permission.add("public_profile");
    permission.add("user_friends");
    permission.add("user_birthday");    

    LoginButton btn=(LoginButton)findViewById(R.id.fbbtn);
    btn.setPublishPermissions(permission); 

   image_profile = (ImageView)findViewById(R.id.imgphoto);

    try {
        PackageInfo info = getPackageManager().getPackageInfo(
                "com.example.testing", 
                PackageManager.GET_SIGNATURES);
        for (Signature signature : info.signatures) {
            MessageDigest md = MessageDigest.getInstance("SHA");
            md.update(signature.toByteArray());
            Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
            }
    }
    catch (Exception e) 
    {
       e.printStackTrace();
    }


}


   private Session.StatusCallback callback =new Session.StatusCallback() 
     {

        @Override
        public void call(Session session, SessionState state, Exception exception) 
        {

            onSessionStateChange(session,state,exception);
        }
    };


     void onSessionStateChange(Session session, SessionState state, Exception exception) 
     {
        if (state.isOpened()) 
        {
            Log.i("facebook", "Logged in...");
            Request.newMeRequest(session, new Request.GraphUserCallback() 
            {

                @Override
                public void onCompleted(GraphUser user, Response response) 
                {

                    if(user!=null)
                    {

                      //here I want get profile picture and show in my imageview...

                       //somthing like this:

                        image_profile.setImageBitMap(image);


                      showMsg(user.getName());
                      showMsg(user.getFirstName());
                      showMsg(user.getLastName());

                      showMsg(user.getProperty("email")+"");
                      showMsg(user.getProperty("gender")+"");

                      showMsg(user.getBirthday());

                      showMsg(user.getId()+"");

                    }
                    else
                    {
                        showMsg("its null");
                        showMsg(response.getError().getErrorMessage());
                    }
                }
            }).executeAsync();

        } 
        else if (state.isClosed()) 
        {
            Log.i("facebook", "Logged out...");
        }
    }


@Override
protected void onResume() {     
    super.onResume();
    uihelper.onResume();
}

@Override
protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
uihelper.onSaveInstanceState(outState);
}

@Override
protected void onPause() {
    super.onPause();
    uihelper.onPause();
}

@Override
protected void onDestroy() {
    super.onDestroy();
    uihelper.onDestroy();
}

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

1 个答案:

答案 0 :(得分:0)

您可以尝试以下链接:

Display FB profile pic in circular image view in Application

我希望这会有所帮助。