2012-06-08 75 views
0

我有沒有辦法從URL獲取圖片(圖片)而無需下載?我使用下面的代碼來獲得流媒體視頻和音頻。但它不適用於圖片。Android - 無需下載即可從網址獲取圖片

public static void IntentPlayer(Context context, Uri uri, int mode){ 
    String type; 
    switch(mode){ 
     case 1: type = "video/*"; break; 
     case 2: type = "audio/*"; break; 
     case 3: type = "image/*"; break;    
     default: return; 
    } 
    Intent intent = new Intent(); 
    intent.setAction(android.content.Intent.ACTION_VIEW); 
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);    
    intent.setDataAndType(uri, type); 
    context.startActivity(intent); 
} 

的logcat:

android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=http://192.168.43.1:6789/mobile_base/Tulips.jpg typ=image/* flg=0x10000000 } 

我不想下載的文件之前,我打開它。我會感謝你的回答。謝謝。

+0

你試圖對圖像做什麼?下載圖像,然後在應用程序的視圖中顯示它? – Stevy888

+0

什麼都沒有。只顯示給用戶。 – Nolesh

+0

顯示如何?在應用程序中,在瀏覽器中,什麼? – Stevy888

回答

3

您不能使用「本機圖像查看器」從網絡上顯示圖像,但是您可以輕鬆地將網址傳遞到默認瀏覽器,並且它會自動爲您加載。您需要爲Android添加一個http://前綴,告訴您正在嘗試使用瀏覽器作爲處理該意圖的活動。

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://scarlettjohansson.com/wholesome.png")); 
startActivity(intent); 
+0

謝謝。但它不適合我。我要先下載圖片。 – Nolesh

+0

另一種選擇是將WebView嵌入到單獨的活動中,並啓動它。 – josephus