Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android-从url获取图片而无需下载_Android_Url_Streaming - Fatal编程技术网

Android-从url获取图片而无需下载

Android-从url获取图片而无需下载,android,url,streaming,Android,Url,Streaming,我想知道有没有一种不用下载就能从URL获取图片(图像)的方法?我使用下面的代码来获取流式视频和音频。但它不适用于图片 public static void IntentPlayer(Context context, Uri uri, int mode){ String type; switch(mode){ case 1: type = "video/*"; break; case 2: type = "audio/*"; break;

我想知道有没有一种不用下载就能从URL获取图片(图像)的方法?我使用下面的代码来获取流式视频和音频。但它不适用于图片

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); 
}
日志:

 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 }
我不想在打开文件之前下载它。谢谢你的回答。谢谢。

您不能使用“本机图像查看器”来显示来自web的图像,但您可以轻松地将url传递到默认浏览器,它会自动为您加载。您需要为Android添加一个
http://
前缀,告知您正试图将浏览器用作处理该意图的活动

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://scarlettjohansson.com/wholesome.png"));
startActivity(intent);
您不能使用“本机图像查看器”来显示来自web的图像,但您可以轻松地将url传递到默认浏览器,它应该会自动为您加载。您需要为Android添加一个
http://
前缀,告知您正试图将浏览器用作处理该意图的活动

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

你想用这个图像做什么?下载图像,然后在应用程序的视图中显示它?然后如何显示?在应用程序中,在浏览器中,什么?上面的方法显示本机活动,这取决于文件的类型。如果我将本地uri传递给它,比如
/mnt/sdcard/tulips.jpg
,它将显示本机图像查看器。但正如我所说的,如果我传递像“…”这样的远程url,它就不起作用了。你打算用这个图像做什么?下载图像,然后在应用程序的视图中显示它?然后如何显示?在应用程序中,在浏览器中,什么?上面的方法显示本机活动,这取决于文件的类型。如果我将本地uri传递给它,比如
/mnt/sdcard/tulips.jpg
,它将显示本机图像查看器。但正如我所说的,如果我传递像“…”这样的远程url,它就不起作用了,谢谢。但这不适合我。我要先下载图片。另一个选择是在单独的活动中嵌入一个网络视图,然后启动它。谢谢。但这不适合我。我要先下载图片。另一个选择是在一个单独的活动中嵌入一个WebView,然后启动它。