我从ftp请求中检索了apk,并且代码可以正常工作,但是它不会更新apk。该代码也没有给出异常。我仍然看到旧的应用程序。该应用程序是设备所有者。它不会更新应用程序,但我看不到错误
@Override
public void run() {
try {
FTPClient ftpClient = new FTPClient();
ftpClient.connect("10.0.0.22");
ftpClient.login("User", "1234");
ftpClient.enterLocalPassiveMode();
String remoteFile1 = "/app-release.apk";
String downPath = context.getCacheDir().getAbsolutePath();
File myapk = new File(downPath + "/app-release.apk");
OutputStream outputStream1 = new BufferedOutputStream(new FileOutputStream(myapk));
boolean success = ftpClient.retrieveFile(remoteFile1, outputStream1);
System.out.println(success);
outputStream1.close();
myapk.setReadable(true, false);
if (!success) {
ftpClient.logout();
ftpClient.disconnect();
return;
} else {
Uri uri = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID + ".provider",myapk);
Intent promptInstall = new Intent(Intent.ACTION_VIEW)
.setDataAndType(uri,"application/vnd.android.package-archive")
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(promptInstall);
}
}
catch (Exception e) {
e.printStackTrace();
Log.e("IO","IO"+e);
}
}