I want to update my APK programmatically with a FTP request. I can connect to my FTP server , but i get a E/IO: IOjava.io.FileNotFoundException: /storage/emulated/0/Download/app-debug.apk (Permission denied) exception.
How can i solved this problem? The application is device owner of the device. And i have the permissons in the Android Manifest. Thats why i dont know why i get a permission denied?
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);
}