Search code examples
androidfacebookdownloadprofileimage

Android: How to wait for the facebook profile picture download?


My goal is to wait for the profile picture download so I can start a video that will use that picture.

I'm using the provided facebook widget: ProfilePictureView to show the picture.

And I'm waiting for the onComplete of executeMeRequestAsync() but this seems to wait for the GraphUser that only contains the picture Id. When I do the setProfileId() of the ProfilePictureView is when it starts downloading the picture.

There's any possibility to have something like that onComplete() that waits for the download using ProfilePictureView? Or I'll need to go for a Bitmap or something, but then How do I make a callback to report that the download of file is completed?

Code that get's the info from FB and onComplete show my button that will start the video

Request.executeMeRequestAsync(session, new Request.GraphUserCallback() {
    public void onCompleted(GraphUser user, Response response) {
        showStartButton();                  
    }               
}); 

Solution

  • For achieve want I want: to have the facebook profile picture downloaded before I go to the next screen I used the loadBitmap method linked by Ming Li inside doInBackground method from AsyncTask.

    onComplete method look like this

    public void onCompleted(GraphUser user, Response response) {
        String id = user.getId();
        String url = "http://graph.facebook.com/" + id + "/picture?type=normal";
        ImageLoader il = new ImageLoader(getActivity());//this class extends AsyncTask<String, Integer, Bitmap>
        il.execute(url);
        showStartButton();                  
    }
    

    So this way I prevent users to continue by using a ProgressDialog that will disappear when the AsyncTask onPostExecute() method is called, meaning that the download is finished.