Reputation: 51
I want to get the facebook profile picture, but it returns me Bitmap null. Why? The debug I get this: Bitmap b = getUserPic (user IDs); b: null byte [] image = convertBitmapToByteArray (b); image: null
public void displayWelcomeMessage(Profile profile){
if (profile != null){
//mTextDetails.setText("Welcome "+ profile.getName());
databaseHelper = new Database(getActivity());
String name = profile.getName();
String idade = profile.getLastName();
String userIds = profile.getId();
Bitmap b = getUserPic(userIds);
byte[] image = convertBitmapToByteArray(b);
long id = databaseHelper.insertData(name, idade, image);
if(id < 0){
Message.message(getActivity(), "Unsuccessful");
} else{
Message.message(getActivity(), "Successfully Inserted a Row");
}
}
}
public Bitmap getUserPic(String userID) {
String imageURL;
Bitmap bitmap = null;
//Log.d(TAG, "Loading Picture");
imageURL = "https://graph.facebook.com/"+userID+"/picture?type=small";
try {
bitmap = BitmapFactory.decodeStream((InputStream)new URL(imageURL).getContent());
} catch (Exception e) {
Log.d("TAG", "Loading Picture FAILED");
e.printStackTrace();
}
return bitmap;
}
Upvotes: 0
Views: 397
Reputation: 31479
Have a look at my answer at
I think this is because Facebook is sending a redirect when you call https://graph.facebook.com/"+userID+"/picture?type=small
.
Upvotes: 1
Reputation: 2696
Try this:
URL url = new URL(imageURL);
Bitmap image = BitmapFactory.decodeStream(url.openConnection().getInputStream());
Upvotes: 0