編輯:關於 Android 程式設計
Android 越來越普及,那已安裝的應用要如何更新呢?應用市場裡常會顯示「某某應用已更新」之類的資訊,我們能否也實現類似功能?要做哪些準備?做過 Web 開發的人都知道,Web 伺服器種類很多,如 Windows 自帶的 IIS、跨平台的 Apache 等。這裡以 IIS 作為伺服器來實現 APK 的更新下載,先來看效果圖。

可以看到,取得更新列表後可根據情況進行更新,下載完成後進行安裝,這樣就完成了一次更新。第一步,我們先自定義更新列表中每一行的控件。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="https://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="64px"
android:paddingLeft="10px"
android:paddingTop="10px"
android:orientation="horizontal">
<ImageView
android:id="@+id/update_item_app_image"
android:layout_width="64px"
android:layout_height="64px"
android:background="@drawable/apk">
</ImageView>
<TextView
android:id="@+id/update_item_app_name"
android:text="TestApk">
</TextView>
<TextView
android:id="@+id/update_item_app_old_version"
android:gravity="right"
android:text="Not Install">
</TextView>
<TextView
android:layout_width="50px"
android:gravity="center"
android:text="->">
</TextView>
<TextView
android:id="@+id/update_item_new_version"
android:gravity="left"
android:text="1.0.0.0">
</TextView>
<Button
android:id="@+id/update_item_behavior"
android:text="Update">
</Button>
</LinearLayout>
說明:
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="https://schemas.android.com/apk/res/android">
<style name="update_item_textview">
<item name="android:layout_width">180px</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_marginLeft">20px</item>
<item name="android:textColor">#000000</item>
<item name="android:textSize">30sp</item>
</style>
<style name="update_item_button">
<item name="android:layout_width">180px</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_marginLeft">20px</item>
<item name="android:textColor">#000000</item>
<item name="android:textSize">30sp</item>
</style>
</resources>
說明:
自定義好更新控件後就能使用了。使用時,要先找到這個佈局,再添加到相應位置。從效果圖看,更新列表是按行分布的,可用多種方式實現,如 RelativeLayout + LinearLayout、ListView + Adapter 等,這裡採用 ListView + Adapter。具體做法請參見〈Android 基於 IIS 的 APK 下載(二)顯示更新列表〉。完整程式碼可於作者的 GitHub 專案 ApkUpdate 取得。
Android XML 解析實務:SAX、DOM 與 Pull 三種方式完整比較
XML 常用於資料交換與設定檔。Android 常見的解析方式有 SAX、DOM 與 Pull,三者都能讀取與產生 XML,但特性與適用情境不同。 SAX SAX 是事
QQ空間直播星星能提現嗎 提現功能現狀說明
在QQ空間開啟直播後,你會收到粉絲送出的禮物——星星。這些星星能兌換成現金提現嗎?小編下面就帶你看清目前的情況。 QQ空間直播提現相關說明: 1、打開QQ空間直播,點擊中
安卓GPU性能測試方法探索
背景在安卓性能測試中,CPU、內存、網絡等指标通常有較成熟的工具支持,但GPU相關指標相對陌生。系統本身沒有直接提供類似top命令的GPU占用率查看方式,因此測試人員往往
自定義 Android Activity 標題欄:requestWindowFeature 與 setFeatureInt
自定義標題欄的關鍵若要把預設標題換成自訂版面,必須先呼叫 requestWindowFeature,並指定 FEATURE_CUSTOM_TITLE。這個步驟必須在 se