【Android】友盟的自動更新組件



前言

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

 

聲明
歡迎轉載,但請保留文章原始出處:)
博客園:http://www.cnblogs.com

農民伯伯: http://over140.cnblogs.com 


正文

一、缺少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還有東西,拷貝進項目即可!吐槽一下,好丑 - - # ,然后就有了下面:

 

二、自定義升級對話框

     /* * 版本檢測  */
     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的統計組件,主要是因為近期博客園把文件下載給封了(必須登錄),然后就不得不找其他辦法了。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM