为什么我无法在Android中检索FaceBook个人资料照片?

时间:2014-04-05 09:24:42

标签: android facebook image

我正在尝试使用Android中的FaceBook Profile pic检索我的Url。我无法检索任何图像。我没有错误日志,但我得到以下日志。 04-05 04:14:41.005: D/skia(2987): --- SkImageDecoder::Factory returned null。我发布了代码。请一步一步告诉我我做错了什么。

   final ImageView photoImageView=(ImageView)findViewById(R.id.imageView1);
    AsyncTask<Void, Void, Bitmap> t = new AsyncTask<Void, Void, Bitmap>(){
    protected Bitmap doInBackground(Void... p) {
       Bitmap bm = null;
        try {
                URL aURL = new URL("http://graph.facebook.com/+"id"+/picture?type=small");
                URLConnection conn = aURL.openConnection();
                conn.setUseCaches(true);
                conn.connect(); 
                InputStream is = conn.getInputStream(); 
                BufferedInputStream bis = new BufferedInputStream(is); 
                bm = BitmapFactory.decodeStream(bis);
                bis.close(); 
                is.close();
               // photoImageView.setImageBitmap(bm);
            } catch (IOException e) { 
                e.printStackTrace(); 
            }
           return bm;
        }

        protected void onPostExecute(Bitmap bm){

               // Drawable drawable = new BitmapDrawable(getResources(), bm);
               photoImageView.setImageBitmap(bm);

            //  photoImageView.setBackgroundDrawable(drawable); 


        }
    };
    t.execute();

2 个答案:

答案 0 :(得分:0)

URL aURL = new URL("https://graph.facebook.com/"+id+"/picture?type=small");

试试这个。

如果id integer转换为string

也不是http,请尝试https

答案 1 :(得分:0)

请尝试以下代码,这对我来说非常有用。

try {
        URL image_value = new URL("http://graph.facebook.com/"+ user.getId()+ "/picture?type=large");
        Bitmap bmp = null;
        try {
                bmp = BitmapFactory.decodeStream(image_value.openConnection().getInputStream());
            } catch (IOException e) {
                    e.printStackTrace();
            }
            profile_pic.setImageBitmap(bmp);
            } catch (MalformedURLException e) {
                    e.printStackTrace();
            }
相关问题