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