I'm trying to download the apk file on the file server via ftp communication. The file is downloaded normally from an Android 13 mobile device, but when tested with an Android-based PDA device called the MC2200, the APK file is not downloaded. For your information, it's Android 10 (API 29).
new Thread(new Runnable() {
@Override
public void run() {
String downloadFolderPath = Environment.getExternalStoragePublicDirectory(DIRECTORY_DOWNLOADS).getPath();
File pdaFolder = new File(downloadFolderPath);
File files[] = pdaFolder.listFiles();
for (int i = 0; i < files.length; i++) {
System.out.println("file: " + files[i]);
}
boolean status = false;
status = connectFTP.ftpConnect("192.168.5.2", "pda", "login1323", 21);
if (status == true) {
Log.d(TAG, "Connection Success");
} else {
Log.d(TAG, "Connection failed");
}
int PERMISSION_REQUEST = 1;
if (ActivityCompat.checkSelfPermission(MainActivity.this,
Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
String[] PERMISSIONS = {Manifest.permission.READ_EXTERNAL_STORAGE};
ActivityCompat.requestPermissions(MainActivity.this, PERMISSIONS, PERMISSION_REQUEST);
}
cVersion = BuildConfig.VERSION_NAME;
System.out.println(BuildConfig.VERSION_NAME);
System.out.println(Build.VERSION.SDK_INT);
for (String fileName : connectFTP.ftpGetFileList("/PDA")) {
if (fileName.endsWith(".apk")) {
serverApkVersion = fileName.replaceAll("^\\(File\\)\\s*", "");
String localFilePath = downloadFolderPath + "/" + serverApkVersion;
if (!cVersion.equals(serverApkVersion.replace(".apk", ""))) {
System.out.println(connectFTP.ftpGetFileList("/PDA").length);
for(String a: connectFTP.ftpGetFileList("/PDA")) {
System.out.println(a);
}
System.out.println(serverApkVersion);
if (connectFTP.ftpDownloadFile("/PDA/" + serverApkVersion, localFilePath)) {
} else {
System.out.println("failed");
}
}
}
}
runOnUiThread(new Runnable() {
@Override
public void run() {
customProgressDialog.dismiss();
Toast.makeText(MainActivity.this, downloadFolderPath, Toast.LENGTH_SHORT).show();
}
});
}
}).start();
On Android 10 devices, FTP CONNECT is normal, and the file list is also output normally. However, when using the ftpDownloadFile() function, it falls into the catch statement.
FileOutputStream fos = new FileOutputStream(desFilePath); The problem seems to occur in the above part.
Is this a problem caused by Android version difference, I don't see what the problem is.
I'll leave the code below.