WEB开发网
开发学院手机开发Android 开发 Android版本检测 自动更新 阅读

Android版本检测 自动更新

 2010-10-19 20:17:10 来源:WEB开发网   
核心提示:}}private void downloadTheFile(final String strPath) {fileEx = strURL.substring(strURL.lastIndexOf(".") + 1, strURL.length()).toLowerCase();fileNa = s

}

}

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 {

上一页  1 2 3 4  下一页

Tags:Android 检测 自动

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接