2012-06-08 76 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