Status Update
Comments
er...@gmail.com <er...@gmail.com>
an...@google.com <an...@google.com> #2
The code above should actually be:
// Write the file
OutputStream outputStream = getContentResolver().openOutputStream(currentUri);
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream );
Actually the problem seems to be with ParcelFileDescriptor.AutoCloseOutputStream . I can get the code above to work fine if I don't use getContentResolver().openOutputStream(currentUri) , which returns a ParcelFileDescriptor.AutoCloseOutputStream .
If I use:
// Write the file
FileOutputStream fos = new FileOutputStream(new File(getFilesDir(), "out.txt"));
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(fos);
it WORKS correctly on any API level.
But as I am using external storage and have to use the ContentProvider given when I get access to the storage via a chooser, all I have to deal with is a content Uri and not a file name nor file handle. I have to go through the getContentResolver methods.
Note that:
// Write the file
ParcelFileDescriptor pfd = getContentResolver().openFileDescriptor(currentUri, "w");
FileDescriptor fd = pfd.getFileDescriptor();
FileOutputStream fos = new FileOutputStream(fd);
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(fos);
Does not work either. Somewhere in the ParcelFile system things are going wrong.
// Write the file
OutputStream outputStream = getContentResolver().openOutputStream(currentUri);
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream );
Actually the problem seems to be with ParcelFileDescriptor.AutoCloseOutputStream . I can get the code above to work fine if I don't use getContentResolver().openOutputStream(currentUri) , which returns a ParcelFileDescriptor.AutoCloseOutputStream .
If I use:
// Write the file
FileOutputStream fos = new FileOutputStream(new File(getFilesDir(), "out.txt"));
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(fos);
it WORKS correctly on any API level.
But as I am using external storage and have to use the ContentProvider given when I get access to the storage via a chooser, all I have to deal with is a content Uri and not a file name nor file handle. I have to go through the getContentResolver methods.
Note that:
// Write the file
ParcelFileDescriptor pfd = getContentResolver().openFileDescriptor(currentUri, "w");
FileDescriptor fd = pfd.getFileDescriptor();
FileOutputStream fos = new FileOutputStream(fd);
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(fos);
Does not work either. Somewhere in the ParcelFile system things are going wrong.
Description
What
User experience
What type of Android issue is this?
User Interface
What steps would let us observe this issue?
What was the effect of this issue on your device usage, such as lost time or work?
High
When
Time and frequency
When did this happen?
Mar 19, 2025 10:00 AM GMT+10:00
How often has this happened?
Every time
Where
Component
Originating component: <not visible> (1684638)
Build and device data
- Build Number: google/komodo_beta/komodo:16/BP22.250221.010/13193326:user/release-keys
(Note: It is the build when sending this report. For exact build reference, please see the attached bugreport.)
Debugging information
Google Play-Dienste
com.google.android.gms
Version 250933035 (25.09.33 (260400-736501638))
System App (Updated)
Android System WebView
com.google.android.webview
Version 699803933 (134.0.6998.39)
System App (Updated)
Network operator: felix
SIM operator: felix
Filed by Android Beta Feedback. Version (Updated): 2.46-betterbug.external_20241023_RC01 (DOGFOOD)https://developer.android.com/preview/feedback#feedback-app .
To learn more about our feedback process, please visit