- 浏览: 18565 次
- 性别:
- 来自: 内蒙古
最新评论
服务器端设计:
设计方法应该有很多,下面介绍我的一种方法:
a.首先在服务器项目下建立一个文件夹来存放APK安装文件:
b.其次在src下建立一个资源文件,apkVersion.properties,属性定义如下写道 :
view plaincopy to clipboardprint?
apkVersion=1 存版本号
apkSize=550kb 大小
apkPath=http://xx8080/srv/apk/Demo.apk 升级文件
apkVersion=1 存版本号
apkSize=550kb 大小
apkPath=http://xx8080/srv/apk/Demo.apk 升级文件
apkVersion=1 存版本号
apkSize=550kb 大小
apkPath=http://xx8080/srv/apk/Demo.apk 升级文件
apkVersion=1 存版本号
apkSize=550kb 大小
apkPath=http://xx8080/srv/apk/Demo.apk 升级文件
c.定义一个servlet来获取资源中的信息:
定义类:UpdateApkServlet.java
view plaincopy to clipboardprint? //获取资源文件信息 static { Properties ppt = new Properties(); try { ppt.load(UpdateApkServlet.class .getResourceAsStream("/apkVersion.properties")); apkVersion = ppt.getProperty("apkVersion"); apkSize = ppt.getProperty("apkSize"); apkPath = ppt.getProperty("apkPath"); } catch (Exception e) { e.printStackTrace(); } } //获取资源文件信息 static { Properties ppt = new Properties(); try { ppt.load(UpdateApkServlet.class .getResourceAsStream("/apkVersion.properties")); apkVersion = ppt.getProperty("apkVersion"); apkSize = ppt.getProperty("apkSize"); apkPath = ppt.getProperty("apkPath"); } catch (Exception e) { e.printStackTrace(); } }
获取资源,然后生成JSON字串返回客户端处理。 注:当客户端版本有更新,服务器端只要把APK文件拷贝到APK目录,然后更新apkVersion.properties文件中的信息就可以了,切记。
客户端设计:
1、 客户端首先获取服务器的版本信息(http方式获取)。
2、 如何获取本地客户端的版本信息 如下参考代码:
view plaincopy to clipboardprint? /** * 得到本地应用的版本信息 * @return */ private int getAPKVersion(){ //APK版本判断 int sdcardVersion = 0; String apkFilePath="sdcard/demo.apk"; //安装包路径 PackageManager pm = getPackageManager(); PackageInfo info = pm.getPackageArchiveInfo(apkFilePath, PackageManager.GET_ACTIVITIES); if(info != null){ sdcardVersion=info.versionCode; //得到版本信息 Log.v(TAG, "Version="+sdcardVersion); } return sdcardVersion; } /** * 得到本地应用的版本信息 * @return */ private int getAPKVersion(){ //APK版本判断 int sdcardVersion = 0; String apkFilePath="sdcard/demo.apk"; //安装包路径 PackageManager pm = getPackageManager(); PackageInfo info = pm.getPackageArchiveInfo(apkFilePath, PackageManager.GET_ACTIVITIES); if(info != null){ sdcardVersion=info.versionCode; //得到版本信息 Log.v(TAG, "Version="+sdcardVersion); } return sdcardVersion; }
3、 版本比较,如果版本相同,则不执行更新,不同才进行更新操作。 这里插入客户端版本设置介绍: 客户端版本设置在AndroidManifest.xml文件中,里面有两个属性可进行版本信息设置, android:versionCode="1" 版本号 android:versionName="1.1" 版本名称 这个版本号需要和服务器端对应。
4、 需要的权限设置
view plaincopy to clipboardprint?
Sdcard访问权限: uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
访问网络权限: uses-permission android:name="android.permission.INTERNET"
Sdcard访问权限: uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
访问网络权限: uses-permission android:name="android.permission.INTERNET"
Sdcard访问权限: uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
访问网络权限: uses-permission android:name="android.permission.INTERNET"
Sdcard访问权限: uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
访问网络权限: uses-permission android:name="android.permission.INTERNET"
5、 更新安装 当用户点击应用时执行检查更新。相关代码参考:
//弹出框提示 view plaincopy to clipboardprint? public Handler handler = new Handler() { public void handleMessage(Message msg) { super.handleMessage(msg); Dialog dialog = new AlertDialog.Builder(MainActivity.this).setTitle("系统更新").setMessage("发现新版本,请更新!") // 设置内容 .setPositiveButton("确定",// 设置确定按钮 new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { pBar = new ProgressDialog(MainActivity.this); pBar.setTitle("正在下载"); pBar.setMessage("请稍候..."); pBar.setProgressStyle(ProgressDialog.STYLE_SPINNER); downFile(apkPath); } }).setNegativeButton("取消", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // 点击"取消"按钮操作 } }).create();// 创建 // 显示对话框 dialog.show(); } }; public Handler handler = new Handler() { public void handleMessage(Message msg) { super.handleMessage(msg); Dialog dialog = new AlertDialog.Builder(MainActivity.this).setTitle("系统更新").setMessage("发现新版本,请更新!") // 设置内容 .setPositiveButton("确定",// 设置确定按钮 new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { pBar = new ProgressDialog(MainActivity.this); pBar.setTitle("正在下载"); pBar.setMessage("请稍候..."); pBar.setProgressStyle(ProgressDialog.STYLE_SPINNER); downFile(apkPath); } }).setNegativeButton("取消", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // 点击"取消"按钮操作 } }).create();// 创建 // 显示对话框 dialog.show(); } }; //下载 view plaincopy to clipboardprint? /** * DOWNLOAD APK FILE BY URL * @param url */ public void downFile(final String url) { pBar.show(); new Thread() { public void run() { HttpClient client = new DefaultHttpClient(); // params[0]代表连接的url HttpGet get = new HttpGet(url); HttpResponse response; try { response = client.execute(get); HttpEntity entity = response.getEntity(); long length = entity.getContentLength(); InputStream is = entity.getContent(); FileOutputStream fileOutputStream = null; if (is != null) { File file = new File(Environment.getExternalStorageDirectory(),"demo.apk"); fileOutputStream = new FileOutputStream(file); byte[] buf = new byte[1024]; int ch = -1; int count = 0; while ((ch = is.read(buf)) != -1) { // baos.write(buf, 0, ch); fileOutputStream.write(buf, 0, ch); count += ch; if (length > 0) { } } } fileOutputStream.flush(); if (fileOutputStream != null) { fileOutputStream.close(); } down(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }.start(); } public void down() { handler.post(new Runnable() { public void run() { pBar.cancel(); update(); } }); } /** * DOWNLOAD APK FILE BY URL * @param url */ public void downFile(final String url) { pBar.show(); new Thread() { public void run() { HttpClient client = new DefaultHttpClient(); // params[0]代表连接的url HttpGet get = new HttpGet(url); HttpResponse response; try { response = client.execute(get); HttpEntity entity = response.getEntity(); long length = entity.getContentLength(); InputStream is = entity.getContent(); FileOutputStream fileOutputStream = null; if (is != null) { File file = new File(Environment.getExternalStorageDirectory(),"demo.apk"); fileOutputStream = new FileOutputStream(file); byte[] buf = new byte[1024]; int ch = -1; int count = 0; while ((ch = is.read(buf)) != -1) { // baos.write(buf, 0, ch); fileOutputStream.write(buf, 0, ch); count += ch; if (length > 0) { } } } fileOutputStream.flush(); if (fileOutputStream != null) { fileOutputStream.close(); } down(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }.start(); } public void down() { handler.post(new Runnable() { public void run() { pBar.cancel(); update(); } }); } //更新升级 view plaincopy to clipboardprint? public void update() { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(new File("/sdcard/demo.apk")),"application/vnd.android.package-archive"); startActivity(intent); } public void update() { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(new File("/sdcard/demo.apk")),"application/vnd.android.package-archive"); startActivity(intent); }
原文地址:http://blog.csdn.net/muyu114/article/details/6623509
发表评论
-
Android中shape的使用
2012-12-19 13:23 914Android中常常使用shape来定义控件的一些显示属性,今 ... -
如何改变Activity在当前任务堆栈中的顺序
2012-10-26 18:31 1524本示例演示如何通过 ... -
android XML积累
2012-05-23 10:02 886JAVA中如果URL中含有中文 需要用 java.net.UR ... -
android 支持的Html标签
2012-05-11 17:37 6031TextView textView=(TextView ... -
android ListView几个比较特别的属性
2012-04-11 09:53 2421由于这两天在做listView的东西,所以整理出来一 ... -
HashMap中的数据按照PUT数据顺序将KEY和VALUE取出来
2012-03-31 09:24 2149如何在JAVA里面将一个HashMap ... -
Java容器类List、ArrayList、Vector及map、HashTable、HashMap的区别与用法
2012-03-29 11:09 897ArrayList 和Vector是采用数组方式存储数据 ... -
Android的layout_weight属性释疑
2012-03-23 13:00 1098Android的layout_weight属 ...
相关推荐
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > android:id="@+id...
本Demo主要实现了安卓(Android)TCP 客户端(Client)和服务器(Server)Demo的Socket通讯。以及对接硬件的项目数据在十六进制&&byte&&int的转换处理。 要注意BufferedReader的readLine()方法的阻塞问题: 读取socket输入...
Android UDP 组播的例子包含Android 组播 Server和Client端 发送端和接收端.zip,太多无法一一验证是否可用,程序如果跑不起来需要自调,部分代码功能进行参考学习。
基于TCP~socket,Android客户端与PC通信,客户端源码。已经测试,可用。附带apk,和网络调试助手,方便测试。只需提供服务器的IP和端口号,... 重点是客户端时时接收服务器端发送来的数据。采用 Handler和Thead结合。
2. UpApk_服务器端放在tomcat_webapps下的文件 3. 在服务端src/com.bc.upgrade.utils 中BsdiffUtil 中设置 a) bsdiff工具地址 b) 旧Apk地址 c) 新Apk地址 d) 生成差异包地址 4. 每次上传新Apk版本需要修改config....
-p 指定服务器端使用的端口或客户端所连接的端口eg:iperf -s -p 9999;iperf -c 222.35.11.23 -p 9999 -u 使用udp协议 -w 指定TCP窗口大小,默认是8KB -B 绑定一个主机地址或接口(当主机有多个地址或接口时使用...
基于TCP~socket,Android客户端与PC通信,客户端源码。已经测试,可用。附带apk,和网络调试助手,方便测试。只需提供服务器的IP和端口号,...重点是客户端时时接收服务器端发送来的数据。采用 Handler和Thead结合。
本系统管理Android应用程序的信息,通过Json与Android客户端进行通信,具有上传APK包,图片功能,Android客户端可以通过访问服务器URL进行包的更新。
每个使用 PHP 轻论坛程序 Carbon Forum 的网站,都可以修改客户端源码中的接口信息,在三分钟内编译出一个专属于自己的 Android 客户端(服务器端也需要升级到最新版本,要不了多久就会发布的)。 官网的 ...
二、运行环境:win32(服务器端)、Android2.1以上版本Android平板或手机。 三、主要技术要点: 1、java Eclipse Web开发,ligerUI界面组件应用,socket接口,SQL Server 2000数据库操作、管理; 2、Android apk开发...
ADB全称Android Debug Bridge, 是android sdk里的一个工具,用这个工具可以直接操作管理android模拟器或者真实的andriod...ADB是一个 客户端-服务器端 程序,其中客户端是你用来操作的电脑, 服务器端是android设备。
网上收集和自己总结的一些android使用资料,比较基础的知识,对...android客户端和服务器端交互.docx Android之从网络上获取图片视频.docx webview属性大全.docx 菜谱aip.docx 反编译Apk得到Java源代码总结.docx
android json解析(包含服务器端,客户端)\JSON解析
Androrat是使用Java Android为客户端开发的客户端/服务器应用程序,而Server使用Python。 AndroRAT将在从Android 4.1(Jelly Bean)到Android 9.0(Oreo)(API 16到API 28)的设备上运行 AndroRAT也可在Android 10...
Android客户端的部分功能需要与服务器端程序通信,请先部署服务器端程序: 编译生成前,请先搜索"TODO-FIRST"( 和 文件中),按注释提示信息,填入必要信息(服务器IP地址等)。 注:中,出于安全考虑,已去除原本...
客户端使用android,服务器端使用struts2+spring2.5+hibernate3.3全注解整合,在struts2中获取android传递的数据,并将从数据库中获取的数据转为json格式传递给android,在android端可以进行分页显示,分页的业务...
此源码是运行在Android智能电视上,包含电视端APK(UDP服务器端)与手机端(UDP客户端)两方面的源码,主要实现的功能如下 1、基于局域网 2、网络接口为无线与有线 3、服务器端接收到客户端的数据需要模拟按键...
关于ADB 在开发调试Android程序时我们需要通过adb工具在我们的手机和电脑之间建立连接,通常情况我们都是使用数据线,其实adb...服务器端通过扫描5555到5585之间的奇数端口来寻找模拟器或设备实例并与找到的建立链接。
一,完成的功能 1. 文字消息发送(有文字和表情) 2. 语音消息发送 ...服务器端发送消息给客户端,采用的是百度云推送。 2.服务器采用的struct2框架 3.Android开发技术,Java编程技术 包括文档与代码