版本更新XML
来源:互联网 发布:微信淘宝下单返利骗局 编辑:程序博客网 时间:2024/05/16 04:11
package test.bwie.com.gaoxuge20160701.utils;import android.app.ProgressDialog;import android.content.Context;import android.content.pm.PackageManager;import android.os.Environment;import android.os.Message;import android.util.Log;import android.util.Xml;import org.xmlpull.v1.XmlPullParser;import java.io.BufferedInputStream;import java.io.File;import java.io.FileOutputStream;import java.io.InputStream;import java.net.HttpURLConnection;import java.net.URL;import test.bwie.com.gaoxuge20160701.R;import test.bwie.com.gaoxuge20160701.bean.VersionBean;/** * Created by gateway on 2016/7/1. */public class VerSionUtils { //获取本应用的版本号 public static int getVerCode(Context context) { int verCode = -1; //注意:"com.example.try_downloadfile_progress"对应AndroidManifest.xml里的package="……"部分 try { verCode = context.getPackageManager().getPackageInfo("test.bwie.com.gaoxuge20160701", 0).versionCode; } catch (PackageManager.NameNotFoundException e) { Log.e("msg", e.getMessage()); } return verCode; } /** * 获取版本名称 * * @param context * @return */ public static String getVerName(Context context) { String verName = ""; try { verName = context.getPackageManager().getPackageInfo("test.bwie.com.gaoxuge20160701", 0).versionName; } catch (Exception e) { Log.e("msg", e.getMessage()); } return verName; } /* * 用pull解析器解析服务器返回的xml文件 (xml封装了版本号) */ public static VersionBean getUpdataInfo(InputStream is) throws Exception { XmlPullParser parser = Xml.newPullParser(); parser.setInput(is, "utf-8");//设置解析的数据源 int type = parser.getEventType(); VersionBean info = new VersionBean();//实体 while (type != XmlPullParser.END_DOCUMENT) { switch (type) { case XmlPullParser.START_TAG: if ("versionName".equals(parser.getName())) { info.setVersionName(parser.nextText()); //获取版本号 } else if ("versionCode".equals(parser.getName())) { info.setVersionCode(parser.nextText()); //获取要升级的APK文件 } else if ("downloadUrl".equals(parser.getName())) { info.setDownloadUrl(parser.nextText()); //获取该文件的信息 } else if ("updateLog".equals(parser.getName())) { info.setUpdateLog(parser.nextText()); //获取该文件的信息 } break; } type = parser.next(); } return info; }}
0 0
- 版本更新XML
- xml解析+版本更新
- 版本更新(xml)方法提出去了
- 安卓项目版本更新(保存xml数据)
- 版本更新
- //版本更新
- 版本更新
- 更新版本
- 版本更新
- 版本更新
- 版本更新
- 版本更新
- 版本更新
- 版本更新
- 版本更新
- 版本更新
- 版本更新
- 版本更新
- 同步分区表
- 计算机网络的体系结构
- Eclipse 平台提供的扩展点
- Java RandomAccessFile用法
- Netty源码解读(四)Netty与Reactor模式
- 版本更新XML
- CKEditor使用中遇到的问题解决
- DIV+CSS与表格建站的差别
- JVM(一)java的执行概要
- EventBus简介
- Rxandroid与MVP的结合(demo)
- 出版商后台系统书名搜索中文问题及后续带来的不能分页问题
- Struts2上传文件及相关总结
- Android开源工具项目集合