Android:友盟的自動更新組件

來源:互聯網
上載者:User

又好又專業的服務能幫開發人員省很多時間。一開始做項目也準備自己來統計資料、自己做自動更新,隨著使用友盟服務的時間增加,漸漸放棄了這種想法,轉而研究如何更充分的使用,這裡分享一下使用自動更新組件的心得。

一、缺少res導致不能升級的問題

由於缺少瞭解,官網文檔也沒用提醒,僅僅拷貝了SDK的jar到工程裡,一直不知道到底升級功能是否已經實現,關鍵是也不報錯!今天又拿出來測試了一下,監聽了一下UmengUpdateListener介面,發現用戶端已經檢測到了更新,但是沒用彈出更新的對話方塊,然後就注意到了如下log:

W/ResourceType(7881): No known package when getting value for resource number 0xffffffff

雖然沒用顯示和umeng有關係,還是重新更新了一下jar,並且反編譯了一下jar查看了一下代碼,並檢查了一下sdk,果然發現少拷貝了資源檔,res下還有drawable、layout、string還有東西,拷貝進項目即可!吐槽一下,好醜 - - # ,然後就有了下面:

查看本欄目更多精彩內容:http://www.bianceng.cnhttp://www.bianceng.cn/OS/extra/

二、自訂升級對話方塊

/** 版本檢測 */    private void checkVersion() {        UmengUpdateAgent.setUpdateOnlyWifi(true);        UmengUpdateAgent.setUpdateAutoPopup(false);        UmengUpdateAgent.setUpdateListener(new UmengUpdateListener() {                @Override            public void onUpdateReturned(int updateStatus,                    UpdateResponse updateInfo) {                if (updateStatus == 0 && updateInfo != null) {                    showUpdateDialog(updateInfo.path, updateInfo.updateLog);                }                // case 0: // has update                // case 1: // has no update                // case 2: // none wifi                // case 3: // time out            }        });            UmengUpdateAgent.update(this);    }        private void showUpdateDialog(final String downloadUrl, final String message) {        AlertDialog.Builder updateAlertDialog = new AlertDialog.Builder(this);        updateAlertDialog.setIcon(R.drawable.app_icon);        updateAlertDialog.setTitle(R.string.app_name);        updateAlertDialog.setMessage(getString(R.string.update_hint, message));        updateAlertDialog.setNegativeButton(R.string.update_ok,                new DialogInterface.OnClickListener() {                    @Override                    public void onClick(DialogInterface dialog, int which) {                        dialog.dismiss();                        try {                            startActivity(new Intent(Intent.ACTION_VIEW, Uri                                    .parse(downloadUrl)));                        } catch (Exception ex) {                            }                    }                }).setPositiveButton(R.string.dialog_no, null);        if (!isFinishing())            updateAlertDialog.show();    }

三、參考

官網文檔:http://dev.umeng.com/doc/document_update_android.html

結束

本來沒打算用umeng的統計組件,主要是因為近期部落格園把檔案下載給封了(必須登入),然後就不得不找其他辦法了。

作者:cnblogs 農民伯伯

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.