0

I am currently developing an application that connects to facebook . Only I have a problem, I want to show the profile picture of the person who agreed on a ImageView ... Does anyone know how to display the profile picture in ImageView ?

I have the following code:

public class Profile_Facebook extends Activity{ private 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);
}
HendraWD
  • 2,984
  • 2
  • 31
  • 45
Luis Olvera
  • 33
  • 1
  • 7

1 Answers1

0

You can try the below link :

Display FB profile pic in circular image view in Application

I hope this will help.

Community
  • 1
  • 1
Sam
  • 452
  • 5
  • 15