rns-mediapicker 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -104,26 +104,43 @@ class FastMediaPickerModule(
|
|
|
104
104
|
activity: Activity,
|
|
105
105
|
type: String,
|
|
106
106
|
) {
|
|
107
|
+
// 1. AUDIO: Use GET_CONTENT but without the chooser for faster return
|
|
107
108
|
if (type == "audio") {
|
|
108
109
|
val intent =
|
|
109
110
|
Intent(Intent.ACTION_GET_CONTENT).apply {
|
|
110
111
|
addCategory(Intent.CATEGORY_OPENABLE)
|
|
111
112
|
this.type = "audio/*"
|
|
113
|
+
// Some devices honor this to disable multi-select UI
|
|
114
|
+
putExtra(Intent.EXTRA_ALLOW_MULTIPLE, false)
|
|
112
115
|
}
|
|
113
|
-
activity.startActivityForResult(
|
|
116
|
+
activity.startActivityForResult(intent, PICKER_REQUEST_CODE)
|
|
114
117
|
return
|
|
115
118
|
}
|
|
116
119
|
|
|
120
|
+
// 2. MODERN PHOTO PICKER (Android 13+):
|
|
121
|
+
// We set the limit to 1 explicitly.
|
|
117
122
|
if (Build.VERSION.SDK_INT >= 33) {
|
|
118
|
-
val intent =
|
|
123
|
+
val intent =
|
|
124
|
+
Intent(MediaStore.ACTION_PICK_IMAGES).apply {
|
|
125
|
+
// This is the key for Android 13+ to return on single tap
|
|
126
|
+
if (type == "image") {
|
|
127
|
+
this.type = "image/*"
|
|
128
|
+
} else if (type == "video") {
|
|
129
|
+
this.type = "video/*"
|
|
130
|
+
}
|
|
131
|
+
// Setting limit to 1 via the extra usually triggers auto-done on click
|
|
132
|
+
// Note: Standard ACTION_PICK_IMAGES is single-select by default
|
|
133
|
+
// unless EXTRA_PICK_IMAGES_MAX is set.
|
|
134
|
+
}
|
|
119
135
|
activity.startActivityForResult(intent, PICKER_REQUEST_CODE)
|
|
120
136
|
return
|
|
121
137
|
}
|
|
122
138
|
|
|
139
|
+
// 3. FALLBACK (Older Androids):
|
|
140
|
+
// Avoid Intent.createChooser to bypass the extra "Open with..." dialog
|
|
123
141
|
val fallback =
|
|
124
142
|
Intent(Intent.ACTION_GET_CONTENT).apply {
|
|
125
143
|
addCategory(Intent.CATEGORY_OPENABLE)
|
|
126
|
-
// FIXED: Explicitly use this.type to refer to Intent property
|
|
127
144
|
this.type =
|
|
128
145
|
when (type) {
|
|
129
146
|
"video" -> "video/*"
|
|
@@ -133,8 +150,9 @@ class FastMediaPickerModule(
|
|
|
133
150
|
if (type == "both") {
|
|
134
151
|
putExtra(Intent.EXTRA_MIME_TYPES, arrayOf("image/*", "video/*"))
|
|
135
152
|
}
|
|
153
|
+
putExtra(Intent.EXTRA_ALLOW_MULTIPLE, false)
|
|
136
154
|
}
|
|
137
|
-
activity.startActivityForResult(
|
|
155
|
+
activity.startActivityForResult(fallback, PICKER_REQUEST_CODE)
|
|
138
156
|
}
|
|
139
157
|
|
|
140
158
|
private fun launchCamera(
|