初学Android,网络应用之访问网络资源(八十六)
2012-11-12 17:06
405 查看
下面程序读取CSDN的logo图片
public class URLTest extends Activity { ImageView show; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); show = (ImageView) findViewById(R.id.show); // 定义一个URL对象 try { URL url = new URL("http://csdnimg.cn/www/images/csdnindex_logo.gif"); // 打开该URL对应的资源的输入流 InputStream is = url.openStream(); // 从InputStream中解析出图片 Bitmap bitmap = BitmapFactory.decodeStream(is); // 使用ImageView显示该图片 show.setImageBitmap(bitmap); is.close(); // 再次打开URL对应的资源的输入流 is = url.openStream(); // 打开手机文件对应的输出流 OutputStream os = openFileOutput("csdnindex_logo.gif" , MODE_WORLD_READABLE); byte[] buff = new byte[1024]; int hasRead = 0; // 将URL对应的资源下载到本地 while((hasRead = is.read(buff)) > 0) { os.write(buff, 0 , hasRead); } is.close(); os.close(); } catch (Exception e) { e.printStackTrace(); } } }
相关文章推荐
- Android开发16——获取网络资源之基础应用
- Android 应用资源---访问资源(Accessing Resources)
- Android之loadUrl访问网络资源与本地资源的方法
- Android上Java网络资源访问(二)使用HttpURLConnection多线程下载
- Android之loadUrl访问网络资源与本地资源的方法
- 访问Android硬件资源の管理网络和Wifi连接
- Android 网络:使用URL访问网络资源,ImageView,下载到本地
- [Android]正确地访问网络资源----Proxy的使用
- 访问Android硬件资源及管理网络和Wifi连接
- Android开发16——获取网络资源之基础应用
- 访问Android硬件资源の管理网络和Wifi连接
- Android跨应用访问资源启动Activity
- Android开发之使用URL访问网络资源
- Android开发16――获取网络资源之基础应用
- 访问Android硬件资源の管理网络和Wifi连接
- 关于Unity打包Android平台应用,访问不到StreamingAssets中的资源问题
- Android 应用资源---访问资源(Accessing Resources)
- Android URL访问网络资源,通过URL加载网络图片
- 在android应用中显示网络资源图片
- android典型应用之访问网络