2014-04-14 65 views
0

我想從Facebook上下載圖片,但是我的位圖始終爲空。如何從Facebook下載圖片圖形API

[ 
private void extractFacebookIcon(String id) 
    { 
    Bitmap bitmap = null; 

    InputStream in = null; 
    try 
    { 
     StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); 
     StrictMode.setThreadPolicy(policy); 

     URL imageURL = new URL("http://graph.facebook.com/"+id+"/picture?type=large"); 

     in = (InputStream) imageURL.getContent(); 

     bitmap = BitmapFactory.decodeStream(in); 
     mFacebookIcon = bitmap; 
    } 
    catch(Throwable e) 
    { 

    }] 

當我在瀏覽器中使用http://graph.facebook.com/"+id+"/picture?type=large,我的瀏覽器重定向我這個鏈接,圖像被打開和位圖可以讀取它。

(」 https://fbcdn-profile-a.akamaihd.net/hprofile-ak-frc3/t1.0-1/c0.0.1.00.1.00/p100x100/969878_592016040843290_1511913922_t.jpg

如何解決這個問題,並宣讀了第一個鏈接,然後位圖是不是空?

+0

不要在主線程上運行網絡操作!覆蓋默認的線程策略是非常草率的 – slinden77

回答