【发布时间】:2013-11-08 07:24:01
【问题描述】:
无法从 android 中的 https url 加载图像。 下面是代码。
imgView = (ImageView) findViewById(R.id.ImageView01);
//imgView.setImageResource(R.drawable.scan);
URL url = new URL("https://idw.ideaservices.net/files/11258/272.jpg");
InputStream content = (InputStream)url.getContent();
Drawable d = Drawable.createFromStream(content , "src");
imgView.setImageDrawable(d);
下面是布局的xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000" >
<ImageView
android:id="@+id/ImageView01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:adjustViewBounds="true"
android:scaleType="fitCenter" />
</RelativeLayout>
来自 flickr 的 https url 中的任何其他图像都会被加载,但不是我指定的那个。 任何使它工作的指针都会对我们有很大的帮助。谢谢。
【问题讨论】:
-
你的错误日志告诉你什么?
-
我刚刚在日志中收到这条消息,
request time failed: java.net.SocketException: Address family not supported by protocol