I wanted to update my Android
application to newer version by downloading it from a server but it didn't work(both in code and manually). here is my code:
MimeTypeMap map = MimeTypeMap.getSingleton();
String ext = MimeTypeMap.getFileExtensionFromUrl(file.getName());
String type = map.getMimeTypeFromExtension(ext);
if (type == null)
type = "application/vnd.android.package-archive";
if(outputFile.exists()) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Uri data = Uri.fromFile(outputFile);
intent.setDataAndType(data, type);
MyContext.startActivity(intent); // this line cause parse error
} else {
// display error message -- not happened in my case
Toast.makeText(MyContext, "File was not downloaded", Toast.LENGTH_LONG).show();
}
I test my downloaded apk(new version) file manually with Google Chrome
and the file downloaded successfully, but it couldn't be installed(Error: app not installed).
Do anybody knows what's wrong? Do i miss something necessary to install new version of application without uninstalling old one(uninstalling old version would wipe out whole data)? please help me.
EDIT: It turns out that file that i tried to install, didn't downloaded completely.