Android版本检测\\自动更新
来源:技术人生 责任编辑:栏目编辑 发表时间:2013-07-01 16:31 点击:次
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;
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;
相关新闻>>
最新推荐更多>>>
- 发表评论
-
- 最新评论 更多>>