Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲

Android 網路圖片與網頁原始碼查看器實作

編輯:關於 Android 程式設計

本文示範兩個實用的小工具:網路圖片查看器與網頁原始碼查看器。

網路圖片查看器

首先需在 AndroidManifest.xml 加入 INTERNET 權限。程式以 HttpURLConnection 下載圖片位元組,再用 BitmapFactory.decodeByteArray 轉成 Bitmap,最後顯示在 ImageView。

網頁原始碼查看器

網頁原始碼查看器會以 HttpURLConnection 取得 HTML 文字,放入 TextView。若內容超過畫面,可用 ScrollView 包住 TextView,讓使用者捲動閱讀。

兩種功能都應處理連線逾時、例外與空白結果,避免網路異常造成應用程式崩潰。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © Android教程網 All Rights Reserved