Skip to content

Commit 146e7fb

Browse files
authored
Merge pull request itinance#890 from egealpay/overwrite-fix-android-10
Fix: Overwrite bug on Android 10
2 parents 36d8ec5 + b7c7bf0 commit 146e7fb

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

android/src/main/java/com/rnfs/RNFSManager.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,15 @@ private InputStream getInputStream(String filepath) throws IORejectionException
115115
return stream;
116116
}
117117

118+
private String getWriteAccessByAPILevel() {
119+
return android.os.Build.VERSION.SDK_INT <= android.os.Build.VERSION_CODES.P ? "w" : "rwt";
120+
}
121+
118122
private OutputStream getOutputStream(String filepath, boolean append) throws IORejectionException {
119123
Uri uri = getFileUri(filepath, false);
120124
OutputStream stream;
121125
try {
122-
stream = reactContext.getContentResolver().openOutputStream(uri, append ? "wa" : "w");
126+
stream = reactContext.getContentResolver().openOutputStream(uri, append ? "wa" : getWriteAccessByAPILevel());
123127
} catch (FileNotFoundException ex) {
124128
throw new IORejectionException("ENOENT", "ENOENT: " + ex.getMessage() + ", open '" + filepath + "'");
125129
}

0 commit comments

Comments
 (0)