zoukankan      html  css  js  c++  java
  • 【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的统计组件,主要是因为近期博客园把文件下载给封了(必须登录),然后就不得不找其他办法了。

  • 相关阅读:
    codeforces 455B A Lot of Games(博弈,字典树)
    HDU 4825 Xor Sum(二进制的字典树,数组模拟)
    hdu 1800 Flying to the Mars(简单模拟,string,字符串)
    codeforces 425A Sereja and Swaps(模拟,vector,枚举区间)
    codeforces 425B Sereja and Table(状态压缩,也可以数组模拟)
    HDU 4148 Length of S(n)(字符串)
    codeforces 439D Devu and Partitioning of the Array(有深度的模拟)
    浅谈sass
    京东楼层案例思维逻辑分析
    浅谈localStorage和sessionStorage
  • 原文地址:https://www.cnblogs.com/over140/p/3176852.html
Copyright © 2011-2022 走看看