I am developing an app that updates independently from the Android Play Store. On start-up it checks for a newer version and downloads the new .apk file from the server if required.
The problem is that the .apk file download url executed by HTTP request, is redirected to a Vodafone landing page asking to change the mobile internet settings. The .apk file downloaded by the app is then actually this html webpage.

Visiting any website through the android internet browser does not get redirected to this page. My MIME settings on the hosting server is correctly set up. I am using the same code, hosting provider and mobile carrier on another project without any problems, although that project is running Toshiba tablets on OS 3.2 and this project is Samsung tablets on OS 4.1.
What can I test or change to get it working, or is it some carrier or tablet/OS related problem? Any help would be appreciated. The related code is included below if someone wants to check it, but as mentioned I have no problems with it on another project.
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);
}
}
I had to set carrier setting to “Do not adapt any sites” through the Android internet browser. After that I added the following code to get it working.
Hope this helps someone else with the same problem.