【问题标题】:Bitmap to Android Facebook User's profile image位图到 Android Facebook 用户的个人资料图像
【发布时间】:2016-02-03 11:21:00
【问题描述】:

我想获取 Facebook 登录用户头像的位图。

我已经在我的应用程序中集成了 facebook 并获得了头像的 url,

但是当我制作它的位图时,位图返回 null。

我的代码:

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());

我想将此位图发送到服务器,但是当它返回 null 时,我卡住了。

我也尝试过下载图片,然后发送位图到服务器,但还是不行。

我也参考了下面的链接但是 Steel 没有结果:

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

【问题讨论】:

    标签: android facebook bitmap


    【解决方案1】:

    遇到同样的问题,通过将 http: 更改为 https: 解决了它:

    希望对你有帮助。

    // 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);
        }
    }
    

    称之为

    new DownloadImage().execute(YOUR_URL);
    

    【讨论】:

    • 编辑了我的答案。并且不要忘记将链接更改为 https。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-20
    • 2014-05-25
    • 2017-09-30
    • 1970-01-01
    • 2023-03-25
    • 1970-01-01
    相关资源
    最近更新 更多