我正在开发一个独立于 Android Play 商店更新的应用程序。在启动时,它会检查更新的版本并在需要时从服务器下载新的 .apk 文件。
问题是由 HTTP 请求执行的 .apk 文件下载 url 被重定向到要求更改移动互联网设置的 Vodafone 登录页面。应用程序下载的 .apk 文件实际上就是这个 html 网页。
通过 android 互联网浏览器访问任何网站都不会被重定向到此页面。我在托管服务器上的 MIME 设置已正确设置。我在另一个项目上使用相同的代码、托管服务提供商和移动运营商没有任何问题,尽管该项目在 OS 3.2 上运行东芝平板电脑,而这个项目是在 OS 4.1 上运行的三星平板电脑。
我可以测试或更改什么以使其正常工作,还是与运营商或平板电脑/操作系统相关的问题?任何帮助,将不胜感激。如果有人想检查它,相关代码包含在下面,但如前所述,我在另一个项目上没有问题。
private class UpdateDownloadTask extends AsyncTask<Void, Void, String> {
HttpClient httpclient;
HttpGet httpget;
HttpResponse response;
HttpEntity httpentity;
OutputStream outputStream;
protected void onPreExecute () {
//do not lock screen or drop connection to server on login
activity.getWindow().addFlags(LayoutParams.FLAG_KEEP_SCREEN_ON);
//initiate progress dialogue to block user input during initial data retrieval
ProcessingDialog = ProgressDialog.show(context, "Please Wait", "Downloading Updates", true,false);
}
@Override
protected String doInBackground(Void... nothing) {
try {
//set timeouts for httpclient
HttpParams httpParameters = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParameters, 5000);
HttpConnectionParams.setSoTimeout(httpParameters, 5000);
//setup http get
httpclient = new DefaultHttpClient(httpParameters);
httpget = new HttpGet(uriApk);
// Execute HTTP Get Request
response = httpclient.execute(httpget);
httpentity = response.getEntity();
//create location to store apk file
String path = Environment.getExternalStorageDirectory() + "/download/";
File file = new File(path);
file.mkdirs(); //if download folder not already exist
File outputFile = new File(file, apkName);
//write downloaded file to location
outputStream = new FileOutputStream(outputFile, false);
httpentity.writeTo(outputStream);
outputStream.flush();
outputStream.close();
return "success";
}
catch (Exception e) {
return "error: " + e.toString();
}
}
@Override
protected void onPostExecute(String result) {
//check if result null or empty
if (result.length() == 0 || result == null) {
Toast.makeText(context, "Could Not Download Updates, Please Try Again. Closing Application.", Toast.LENGTH_LONG).show();
activity.finish();
}
//update downloaded
if (result.equals("success")) {
//install downloaded .apk file
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(Environment.getExternalStorageDirectory() + "/download/" + apkName)), "application/vnd.android.package-archive");
activity.startActivity(intent);
//activity.finish();
}
//update not downloaded
else {
Toast.makeText(context, "Could Not Download Updates, Please Try Again. Closing Application.", Toast.LENGTH_LONG).show();
activity.finish();
}
//close update dialog
try {
ProcessingDialog.dismiss();
} catch (Exception e) {
// nothing
}
//release screen lock
activity.getWindow().clearFlags(LayoutParams.FLAG_KEEP_SCREEN_ON);
}
}