- 浏览: 417332 次
- 性别:
文章分类
最新评论
-
wrw_ahut:
你这个怎么停下来?怎么跳转activity
Android启动界面实现 -
huiqoo:
高仿UC半透明MENU菜单(有图有真相) -
wenzhixin:
多谢分享~
Android启动界面实现 -
orange9711:
学习学习
Android启动界面实现 -
qinweiping:
问下楼主 好像这个反编译 只能看到程序的主体结构吧 还是和源程 ...
APK反编译利器Apktool下载及用法介绍
package com.hiyo.game.pdk.tool; import java.io.File; import java.io.FileOutputStream; import java.io.InputStream; import java.net.URL; import java.net.URLConnection; import android.app.Activity; import android.app.AlertDialog; import android.app.ProgressDialog; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.pm.PackageInfo; import android.content.pm.PackageManager.NameNotFoundException; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.net.Uri; import android.util.Log; import android.webkit.URLUtil; import com.hiyo.game.pdk.activity.R; /** * Android AutoUpdate. * * lazybone/2010.08.20 * * 1.Set apkUrl. * * 2.check(). * * 3.add delFile() method in resume()\onPause(). */ public class MyAutoUpdate { public Activity activity = null; public int versionCode = 0; public String versionName = ""; private static final String TAG = "AutoUpdate"; private String currentFilePath = ""; private String currentTempFilePath = ""; private String fileEx = ""; private String fileNa = ""; private String strURL = "http://127.0.0.1:81/ApiDemos.apk"; private ProgressDialog dialog; public MyAutoUpdate(Activity activity) { this.activity = activity; getCurrentVersion(); } public void check() { if (isNetworkAvailable(this.activity) == false) { return; } if (true) {// Check version. showUpdateDialog(); } } public static boolean isNetworkAvailable(Context ctx) { try { ConnectivityManager cm = (ConnectivityManager) ctx .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = cm.getActiveNetworkInfo(); return (info != null && info.isConnected()); } catch (Exception e) { e.printStackTrace(); return false; } } public void showUpdateDialog() { @SuppressWarnings("unused") AlertDialog alert = new AlertDialog.Builder(this.activity) .setTitle("Title") .setIcon(R.drawable.icon) .setMessage("Update or not?") .setPositiveButton("Update", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { downloadTheFile(strURL); showWaitDialog(); } }) .setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }).show(); } public void showWaitDialog() { dialog = new ProgressDialog(activity); dialog.setMessage("Waitting for update..."); dialog.setIndeterminate(true); dialog.setCancelable(true); dialog.show(); } public void getCurrentVersion() { try { PackageInfo info = activity.getPackageManager().getPackageInfo( activity.getPackageName(), 0); this.versionCode = info.versionCode; this.versionName = info.versionName; } catch (NameNotFoundException e) { e.printStackTrace(); } } private void downloadTheFile(final String strPath) { fileEx = strURL.substring(strURL.lastIndexOf(".") + 1, strURL.length()) .toLowerCase(); fileNa = strURL.substring(strURL.lastIndexOf("/") + 1, strURL.lastIndexOf(".")); try { if (strPath.equals(currentFilePath)) { doDownloadTheFile(strPath); } currentFilePath = strPath; Runnable r = new Runnable() { public void run() { try { doDownloadTheFile(strPath); } catch (Exception e) { Log.e(TAG, e.getMessage(), e); } } }; new Thread(r).start(); } catch (Exception e) { e.printStackTrace(); } } private void doDownloadTheFile(String strPath) throws Exception { Log.i(TAG, "getDataSource()"); if (!URLUtil.isNetworkUrl(strPath)) { Log.i(TAG, "getDataSource() It's a wrong URL!"); } else { URL myURL = new URL(strPath); URLConnection conn = myURL.openConnection(); conn.connect(); InputStream is = conn.getInputStream(); if (is == null) { throw new RuntimeException("stream is null"); } File myTempFile = File.createTempFile(fileNa, "." + fileEx); currentTempFilePath = myTempFile.getAbsolutePath(); FileOutputStream fos = new FileOutputStream(myTempFile); byte buf[] = new byte[128]; do { int numread = is.read(buf); if (numread <= 0) { break; } fos.write(buf, 0, numread); } while (true); Log.i(TAG, "getDataSource() Download ok..."); dialog.cancel(); dialog.dismiss(); openFile(myTempFile); try { is.close(); } catch (Exception ex) { Log.e(TAG, "getDataSource() error: " + ex.getMessage(), ex); } } } private void openFile(File f) { Intent intent = new Intent(); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setAction(android.content.Intent.ACTION_VIEW); String type = getMIMEType(f); intent.setDataAndType(Uri.fromFile(f), type); activity.startActivity(intent); } public void delFile() { Log.i(TAG, "The TempFile(" + currentTempFilePath + ") was deleted."); File myFile = new File(currentTempFilePath); if (myFile.exists()) { myFile.delete(); } } private String getMIMEType(File f) { String type = ""; String fName = f.getName(); String end = fName .substring(fName.lastIndexOf(".") + 1, fName.length()) .toLowerCase(); if (end.equals("m4a") || end.equals("mp3") || end.equals("mid") || end.equals("xmf") || end.equals("ogg") || end.equals("wav")) { type = "audio"; } else if (end.equals("3gp") || end.equals("mp4")) { type = "video"; } else if (end.equals("jpg") || end.equals("gif") || end.equals("png") || end.equals("jpeg") || end.equals("bmp")) { type = "image"; } else if (end.equals("apk")) { type = "application/vnd.android.package-archive"; } else { type = "*"; } if (end.equals("apk")) { } else { type += "/*"; } return type; } }
本文转载自:Android版本检测\自动更新 http://www.eoeandroid.com/thread-117764-1-1.html
发表评论
-
解决Android SDK Manager国内下载缓慢的问题
2014-10-26 23:01 626点击Android SDK Manager菜单Tools-& ... -
Android Launcher一些资源
2012-01-10 16:03 1514棒槌网@Android相关文章推荐: rjJ-ZRs\ An ... -
卡刷rom固件update.zip的制作教程
2011-12-29 19:44 19100对于第三方ROM来讲,通常都包括两部分,一个recover ... -
APK反编译利器Apktool下载及用法介绍
2011-12-29 19:40 6471近期在研究rom过程中发现一个非常不错的软件,可以帮助我们把A ... -
制作rom利器bootimg
2011-12-29 19:22 2755打包: bootimg ... -
高仿UC半透明MENU菜单(有图有真相)
2011-11-13 15:55 1917转载自:http://www.eoeandroid.com/ ... -
Android启动界面实现
2011-11-13 15:39 6737转载自:http://www.eoeandroid.com/t ... -
获取本机外网IP地址(External IP Address)
2010-12-15 22:45 6704import java.io.IOException; ... -
Red5+OpenOffice+OpenMeetings架设视频会议网络
2009-07-01 09:57 2205因工作需要,这两天弄了一个视频会议服务器。采用了flash流媒 ... -
J2EE or J2SE? JNDI works with both
2009-05-11 16:21 1479J2EE or J2SE? JNDI works with b ... -
脚本启动Java应用程序(Windows/Linux)
2009-05-08 16:40 36441、新建文件夹myapp,放你的应用; 2、将你的程序 ... -
破解Java程序
2007-12-13 17:36 1857第一步是定位,这也是 ... -
WebSphere 应用服务器环境搭建实践指南
2007-08-22 18:20 5182Dan Wu (wdan@cn.ibm.com), 高级信息工 ... -
beanutils研究心得
2007-01-23 15:47 2089Beanutils用了魔术般的反射技术,实现了很多夸张有用的功 ... -
apache-common功能列表
2007-01-23 15:16 4955... -
Apache Commons工具集简介[转载]
2007-01-21 02:20 5562js 代码 <script ... -
利用servlet生成简单的验证码
2007-01-21 01:47 1578在web.xml配置: 代码 < ... -
实战篇:设计自己的Annotation
2007-01-21 01:44 1329From:http://lighter.iteye.com 第 ... -
JSTL 入门: 表达式语言
2007-01-15 11:23 1379JSP 标准标记库(JSP Stand ... -
extremeTable介绍
2007-01-10 11:14 45361、何为 extremeTable,又一个开源taglib e ...
相关推荐
Android项目版本检测自动更新.rar
获取服务器端XML文件,解析XML获取到最新版本号,与当前软件版本号进行对比,发现不一样则提示更新。 涉及到内容点: 1.远程获取XML并分析XML内容 2.远程下载文件并打开 3.下载时通知栏显示下载进度
安卓Android源码——版本检测自动更新.zip
版本检测自动更新_Android
实现 android7、8 以上版本自动更新app 程序,仅供参考。
安卓Android源码——版本检测自动更新.rar
android检测版本自动更新并弹出对话框提示用户下载,带有进度条,服务端解析xml,已测过好多次,主要包名更签名!
一般android app应用程序会隔一段时间发布一个新的版本,包括新增功能和修复原程序bug,当你打开某个app,如果检测到有最新的版本,会提醒你是否下载更新。
Andorid项目源码 版本检测自动更新完整版
自己做了个android程序的自动检测更新,这里没有服务器的java文件,仅在客户端操作,apk包存放在FTP服务上,内有注释说明。 1.检测是否有更新 2.下载apk包 3.安装apk 4.重新启动
Android应用源码版本检测自动更新.zip项目安卓应用源码下载Android应用源码版本检测自动更新.zip项目安卓应用源码下载 1.适合学生毕业设计研究参考 2.适合个人学习研究参考 3.适合公司开发项目技术参考
用于android程序自动检测更新,里面包含检测是否有更新,有更新可以选择更新
实现Android apk中的自动更新检测和静默升级
Android自动检测版本及自动升级
Android 应用开发源码 参考与学习使用
版本检测自动更新.zip
Android实现自动检测更新apk文件