我想從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
,我的瀏覽器重定向我這個鏈接,圖像被打開和位圖可以讀取它。
如何解決這個問題,並宣讀了第一個鏈接,然後位圖是不是空?
不要在主線程上運行網絡操作!覆蓋默認的線程策略是非常草率的 – slinden77