【发布时间】:2016-01-27 11:50:49
【问题描述】:
我需要在没有 Google Play 的情况下更新我的应用程序。所以我将我的 apk 上传到我的服务器,以便在需要时下载。
通过以下代码可以正常下载,但是当启动安装意图时,它会抛出:“Parse Error: There is a problem parsing the package”
如果我尝试手动运行下载的 apk,它仍然会出现同样的错误。
但是,如果我通过 USB 传输 apk 然后运行它,它会顺利安装。所以这个问题与apk本身无关。
这是我的任务类:
class Update implements Runnable {
@Override
public void run() {
FTPClient ftpClient = new FTPClient();
try {
ftpClient.connect(InetAddress.getByName("mysite.com"));
ftpClient.login("mysite.com", "123456"));
ftpClient.enterLocalPassiveMode();
String remoteFile1 = "/httpdocs/program/app-release.apk";
String downPath = getExternalStoragePublicDirectory(DIRECTORY_DOWNLOADS).getAbsolutePath();
File myapk = new File(downPath + "/app-release.apk");
OutputStream outputStream1 = new BufferedOutputStream(new FileOutputStream(myapk));
boolean success = ftpClient.retrieveFile(remoteFile1, outputStream1);
outputStream1.close();
myapk.setReadable(true, false);
if (!success) {
ftpClient.logout();
ftpClient.disconnect();
return;
} else {
Intent promptInstall = new Intent(Intent.ACTION_VIEW)
.setDataAndType(Uri.fromFile(myapk), "application/vnd.android.package-archive")
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(promptInstall);
}
}
catch (Exception ex) {
//catch exception
}
}
}
【问题讨论】:
-
问题必须在您的下载代码中。看来apk文件下载不成功。
-
@FebiMathew 可能是的,但我看不到。
-
此链接可能会对您有所帮助。 stackoverflow.com/questions/4967669/…
-
@FebiMathew 好吧,现在我尝试使用 HttpURLConnection 而不是 FTPClient 重写下载代码。还是一样的错误。
标签: java android android-asynctask ftp ftp-client