У меня проблема при записи 1 файла в другое приложение. С android api <29 нормально работает. Но при доступе к ошибке android api> 29 я добавляю:
android:requestLegacyExternalStorage="true"
android:usesCleartextTraffic="true"
tools:targetApi="q"
в manifest. И напишите код в другое приложение:
String nameFile = "abc.png";
String folderTargetApp = "test";
CommonUtils.showLogDebug(">>>" + linkFile);
File fileFolderMyApp =
progressBar.getContext().getExternalFilesDir("testve/" + folderTargetApp);
if (fileFolderMyApp != null) {
String pathFolderTarget = fileFolderMyApp.getAbsolutePath().replace(progressBar.getContext().getPackageName(), KEY_PACKAGE_TARGET_APP);
File fileFolderTarget = new File(pathFolderTarget, nameFile);
String linkEncode;
try {
URL url = new URL(linkFile);
linkEncode = url.getProtocol() + "://" + url.getHost() + URLEncoder.encode(url.getPath(), StandardCharsets.UTF_8.toString())
.replace("%2F", "/").replace("+", "%20");
} catch (UnsupportedEncodingException | MalformedURLException e) {
CommonUtils.showLogDebug("error" + e.getMessage());
linkEncode = linkFile;
}
Ion.with(mProgressBar.getContext())
.load(linkEncode)
.progress((downloaded, total) -> {
CommonUtils.showLogDebug("downloaded:" + downloaded + "/" + total);
calcProgressToView(downloaded, total);
})
.write(fileFolderTarget)
.setCallback((e, file) -> {
setVisibilityLoading(false);
if (e != null && e.getMessage() != null) {
CommonUtils.showLogDebug(e.getMessage());
setFailIResultListener(e.getMessage());
return;
}
if (file == null) {
setFailIResultListener("Write file null !");
return;
}
setSuccessIResultListener(Uri.fromFile(file));
});
} else {
String messageFail = "Fail File Path!";
CommonUtils.showLogDebug(messageFail);
setFailIResultListener(messageFail);
}