I haven't tested your code, but I've already discovered my mistake. When I tested the modification in jform.java , I simply deleted the file I had just created with the create intent.
This is actually useless. But chatgpt suggested an approach that I'm going to try to implement.
It seems pretty simple to me:
1. Create the file "filename.zip" for the first time and store the URI.
2. Use the stored URI for future write operations.
That is, when filename.zip is created, the URI will be stored.
When using the Create intent again , it will be possible to delete the stored URI so that filename.zip is created and not filename(1).zip.
Let's see? Sorry for the mistake.
import android.content.SharedPreferences;
import android.net.Uri;
// Store the URI in SharedPreferences
private void saveFileUri(Uri uri) {
SharedPreferences prefs = getSharedPreferences("my_prefs", MODE_PRIVATE);
SharedPreferences.Editor editor = prefs.edit();
editor.putString("file_uri", uri.toString());
editor.apply();
}
// Retrieve the URI from SharedPreferences
private Uri getFileUri() {
SharedPreferences prefs = getSharedPreferences("my_prefs", MODE_PRIVATE);
String uriString
= prefs.
getString("file_uri",
null); if (uriString != null) {
return Uri.parse(uriString);
}
return null;
}