Skip to content

Commit 5e6187a

Browse files
committed
fix(android): cpExternal error on pre API 29
Closes #20
1 parent 018eb13 commit 5e6187a

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

android/src/main/java/com/alpha0010/fs/FileAccessModule.kt

+15-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,21 @@ class FileAccessModule(reactContext: ReactApplicationContext) : ReactContextBase
130130
"audio" -> {
131131
reactApplicationContext.contentResolver.insert(
132132
MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
133-
ContentValues().apply { put(MediaStore.Audio.Media.DISPLAY_NAME, targetName) }
133+
ContentValues().apply {
134+
put(MediaStore.Audio.Media.DISPLAY_NAME, targetName)
135+
136+
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.Q) {
137+
// Older versions require path be specified.
138+
@Suppress("DEPRECATION")
139+
put(
140+
MediaStore.Audio.AudioColumns.DATA,
141+
File(
142+
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC),
143+
targetName
144+
).absolutePath
145+
)
146+
}
147+
}
134148
)
135149
}
136150
"images" -> {

0 commit comments

Comments
 (0)