@@ -6,7 +6,6 @@ import android.content.Intent
6
6
import android.content.pm.PackageManager
7
7
import android.content.res.Configuration
8
8
import android.database.Cursor
9
- import android.graphics.Bitmap
10
9
import android.net.Uri
11
10
import android.os.Build
12
11
import android.os.Bundle
@@ -33,7 +32,6 @@ import com.google.android.material.bottomsheet.BottomSheetDialogFragment
33
32
import com.mahdiasd.filepicker.databinding.FilePickerFragmentBinding
34
33
import kotlinx.coroutines.FlowPreview
35
34
import java.io.File
36
- import java.io.FileOutputStream
37
35
38
36
39
37
class FilePickerFragment : BottomSheetDialogFragment () {
@@ -51,6 +49,7 @@ class FilePickerFragment : BottomSheetDialogFragment() {
51
49
private lateinit var config: FilePicker
52
50
private var storageIsOpen = false
53
51
private var cameraImagePath = " "
52
+
54
53
companion object {
55
54
fun newInstance () = FilePickerFragment ()
56
55
}
@@ -69,6 +68,7 @@ class FilePickerFragment : BottomSheetDialogFragment() {
69
68
else
70
69
initSectionList()
71
70
71
+
72
72
return binding.root
73
73
}
74
74
@@ -147,7 +147,7 @@ class FilePickerFragment : BottomSheetDialogFragment() {
147
147
storageIsOpen = true
148
148
val intent = Intent ()
149
149
.setType(" */*" )
150
- .setAction(Intent .ACTION_OPEN_DOCUMENT )
150
+ .setAction(Intent .ACTION_GET_CONTENT )
151
151
.putExtra(Intent .EXTRA_ALLOW_MULTIPLE , config.maxSelection > 1 )
152
152
storageLauncher.launch(intent)
153
153
@@ -219,21 +219,6 @@ class FilePickerFragment : BottomSheetDialogFragment() {
219
219
}
220
220
}
221
221
222
- private fun saveBitmapToStorage (bitmap : Bitmap ? ): File ? {
223
- if (bitmap == null ) return null
224
- val imagesDir = Environment .getExternalStoragePublicDirectory(Environment .DIRECTORY_DOWNLOADS ).path + File .separator + System .currentTimeMillis() + " .png"
225
- val file = File (imagesDir)
226
- return try {
227
- val fos = FileOutputStream (file)
228
- bitmap.compress(Bitmap .CompressFormat .PNG , 100 , fos)
229
- fos.close()
230
- if (file.exists()) file
231
- else null
232
- } catch (e: Exception ) {
233
- null
234
- }
235
- }
236
-
237
222
238
223
@OptIn(FlowPreview ::class )
239
224
private var storageLauncher = registerForActivityResult(ActivityResultContracts .StartActivityForResult ()) { result ->
@@ -506,7 +491,11 @@ class FilePickerFragment : BottomSheetDialogFragment() {
506
491
}
507
492
508
493
fun btn (view : View ? ) {
509
- config.listener?.selectedFiles(selectedFiles)
494
+ val uris: MutableList <Uri > = ArrayList ()
495
+ selectedFiles.forEach {
496
+ getUriFromFile(it.file)?.let { it1 -> uris.add(it1) }
497
+ }
498
+ config.listener?.selectedFiles(selectedFiles, uris)
510
499
selectedFiles.clear()
511
500
dismiss()
512
501
}
0 commit comments