Android 实现版本检测\自动更新
2010-09-10 00:31:00 来源:WEB开发网曾经用到过的一个Android工具类,版本检测、自动更新。通用性差,权当笔记。
view plaincopy to clipboardprint?
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) {
更多精彩
赞助商链接