取消自动更新,增强版本文件格式检查,解决格式错误引起的崩溃
This commit is contained in:
@@ -111,8 +111,8 @@ public class MainActivity extends Activity {
|
||||
InputMethodManager IMM;
|
||||
ProgressBar pgb1;
|
||||
String urlo = "", HTRE = "", ptitle = "", urln = "";
|
||||
String urlVersion = "https://www.gitlink.org.cn/api/sonichy/HTYBrowser/raw?filepath=version&ref=master";
|
||||
String urlUpdate = "https://www.gitlink.org.cn/api/sonichy/HTYBrowser/raw?filepath=app.apk&ref=master";
|
||||
String url_version = "https://www.gitlink.org.cn/api/sonichy/HTYBrowser/raw?filepath=version&ref=master";
|
||||
String url_update = "https://www.gitlink.org.cn/api/sonichy/HTYBrowser/raw?filepath=app.apk&ref=master";
|
||||
CustomViewCallback customViewCallback;
|
||||
boolean isFullScreen, isManualCheckUpdate = false;
|
||||
static File dir;
|
||||
@@ -241,7 +241,6 @@ public class MainActivity extends Activity {
|
||||
checkUpdate();
|
||||
}
|
||||
};
|
||||
new Thread(CU).start();
|
||||
|
||||
receiver = new DownloadCompleteReceiver();
|
||||
IntentFilter intentFilter = new IntentFilter();
|
||||
@@ -1171,7 +1170,7 @@ public class MainActivity extends Activity {
|
||||
// 添加一个下载任务
|
||||
long downloadId = downloadManager.enqueue(request);
|
||||
Log.e(Thread.currentThread().getStackTrace()[2] + "", downloadId + "");
|
||||
if(surl == urlUpdate){
|
||||
if (surl == url_update) {
|
||||
downloadIdUpdate = downloadId;
|
||||
}
|
||||
}
|
||||
@@ -1179,14 +1178,23 @@ public class MainActivity extends Activity {
|
||||
void checkUpdate() {
|
||||
try {
|
||||
String versionL = MainActivity.this.getPackageManager().getPackageInfo(MainActivity.this.getPackageName(), 0).versionName;
|
||||
URL url = new URL(urlVersion);
|
||||
URL url = new URL(url_version);
|
||||
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||
//conn.setRequestMethod("GET");
|
||||
//if (conn.getResponseCode() == 200) {
|
||||
InputStream IS = conn.getInputStream();
|
||||
InputStreamReader ISR = new InputStreamReader(IS);
|
||||
BufferedReader bufferReader = new BufferedReader(ISR);
|
||||
String versionS = bufferReader.readLine();
|
||||
BufferedReader BR = new BufferedReader(ISR);
|
||||
String versionS = BR.readLine();
|
||||
if (!versionS.startsWith("{") && !versionS.endsWith("}")) {
|
||||
Looper.prepare();
|
||||
Toast.makeText(getApplicationContext(), "服务器版本号解析错误:\n" + versionS, Toast.LENGTH_SHORT).show();
|
||||
Looper.myLooper().loop();
|
||||
return;
|
||||
} else {
|
||||
versionS = versionS.replace("{", "");
|
||||
versionS = versionS.replace("}", "");
|
||||
}
|
||||
Log.e(Thread.currentThread().getStackTrace()[2] + "", versionS + " > " + versionL + " ?");
|
||||
String[] AVersionS = versionS.split("\\.");
|
||||
String[] AVersionL = versionL.split("\\.");
|
||||
@@ -1200,7 +1208,7 @@ public class MainActivity extends Activity {
|
||||
builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
downloadBySystem(urlUpdate, "", "", "", "HTYBrowser.apk");
|
||||
downloadBySystem(url_update, "", "", "", "HTYBrowser.apk");
|
||||
}
|
||||
});
|
||||
builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
|
||||
@@ -1212,7 +1220,7 @@ public class MainActivity extends Activity {
|
||||
dialog.show();
|
||||
Looper.myLooper().loop();
|
||||
} else {
|
||||
if(isManualCheckUpdate) {
|
||||
if (isManualCheckUpdate) {
|
||||
Looper.prepare();
|
||||
Toast.makeText(getApplicationContext(), "当前版本 " + versionL + " >= 服务器版本 "+ versionS + ",是最新的版本", Toast.LENGTH_SHORT).show();
|
||||
Looper.myLooper().loop();
|
||||
@@ -1220,10 +1228,9 @@ public class MainActivity extends Activity {
|
||||
Log.e("检查更新: ", "当前版本是最新的版本");
|
||||
}
|
||||
//}
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Toast.makeText(getApplicationContext(), e.toString(), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user