我想通过FTP请求以编程方式更新我的APK。我可以连接到FTP服务器,但得到一个E / IO:IOjava.io.FileNotFoundException:/storage/emulated/0/Download/app-debug.apk(权限被拒绝)异常。
我该如何解决这个问题?该应用程序是设备的设备所有者。我在Android清单中有权限。那就是为什么我不知道为什么我会拒绝权限的原因?
public void run() {
try {
FTPClient ftpClient = new FTPClient();
ftpClient.connect("10.0.2.2");
ftpClient.login("user", "1234");
ftpClient.enterLocalPassiveMode();
String remoteFile1 = "/app-debug.apk";
String downPath = getExternalStoragePublicDirectory(DIRECTORY_DOWNLOADS).getAbsolutePath();
File myapk = new File(downPath + "/app-debug.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 e) {
e.printStackTrace();
Log.e("IO","IO"+e);
}