1

I want to get Bitmap of the Facebook login user's profile picture.

I have integrate facebook in my application and got the url of profile picture,

But when i make bitmap of it ,bitmap returns null.

My Code :

String fbUID=variable.FacebookUserId;

String img ="http://graph.facebook.com" + File.separator
                        + fbUID + File.separator + "picture";
System.out.println("Image for Home" + img);
img_value = new URL(img);
Bitmap mIcon1 = BitmapFactory.decodeStream(img_value.openConnection().getInputStream());

I want to send this bitmap to server, But as it returns null , I got stuck.

I have also tried to download image and then send bitmap to server but it also not work.

I have also refer below links But Steel no result:

Android and Facebook: How to get picture of logged in User

How to get facebook profile picture of user in facebook SDK Android

Android - get facebook profile picture

Community
  • 1
  • 1
AmeeJoshi
  • 201
  • 2
  • 14

1 Answers1

1

Had faced the same issue solved it by changing http: as https:

Hope it helps.

// DownloadImage AsyncTask
private class DownloadImage extends AsyncTask<String, Void, Bitmap> {

    @Override
    protected void onPreExecute() {
        super.onPreExecute();

    }

    @Override
    protected Bitmap doInBackground(String... URL) {

        String imageURL = URL[0];

        Bitmap bitmap = null;
        try {
            // Download Image from URL
            InputStream input = new java.net.URL(imageURL).openStream();
            // Decode Bitmap
            bitmap = BitmapFactory.decodeStream(input);
            SaveImage(bitmap);

        } catch (Exception e) {
            e.printStackTrace();
        }
        return bitmap;
    }

    @Override
    protected void onPostExecute(Bitmap result) {
        // Set the bitmap into ImageView
        imageview.setImageBitmap(result);
    }
}

call it as

new DownloadImage().execute(YOUR_URL);
DroidAks
  • 327
  • 2
  • 9