I don\'t know why, but I am always getting null when I try to get the profile picture of the user. Do I need to set some specific permissions to get access?
Below is
You are getting null because the call to URL.openConnection() (or any other mechanism to fetch the image) is asynchronous. It returns after your line: return bitmap;
. Therefore bitmap is always null.
I suggest using a callback instead.
This is what i did:
final AQuery androidQuery = new AQuery(this);
AjaxCallback imageCallback = new AjaxCallback() {
@Override
public void callback(String url, byte[] avatar, AjaxStatus status) {
if (avatar != null) {
save(avatar);
} else {
Log.e(TAG, "Cannot fetch third party image. AjaxStatus: " + status.getError());
}
}
};
androidQuery.ajax(imageUrl, byte[].class, imageCallback);
Android query allows you to get the image in different formats (e.g. byte array, Bitmap, etc.). There are other libraries out there, but the idea is the same.