Skip to content

Commit da382b1

Browse files
committed
Use system attachment picker by default
The default for `useSystemPicker` and `useDefaultSystemMediaPicker` has been changed from `false` to `true`. This makes the system's native file/media picker the default option, which doesn't require explicit storage permissions in the app. The in-app picker can still be used by setting this flag to `false`. Documentation and sample apps have been updated to reflect this change and include the necessary permissions for when the in-app picker is enabled.
1 parent 1abacce commit da382b1

File tree

7 files changed

+81
-20
lines changed

7 files changed

+81
-20
lines changed

stream-chat-android-compose-sample/src/main/AndroidManifest.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,21 @@
2222
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
2323
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
2424

25+
<!-- Storage permissions for in-app attachment picker (useSystemPicker = false) -->
26+
<uses-permission
27+
android:name="android.permission.READ_EXTERNAL_STORAGE"
28+
android:maxSdkVersion="32"
29+
/>
30+
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
31+
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
32+
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
33+
34+
<!-- Storage permission for downloading attachments (Android 9 and below) -->
35+
<uses-permission
36+
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
37+
android:maxSdkVersion="29"
38+
/>
39+
2540
<application
2641
android:name="io.getstream.chat.android.compose.sample.ChatApp"
2742
android:allowBackup="false"

stream-chat-android-compose-sample/src/main/java/io/getstream/chat/android/compose/sample/ui/MessagesActivity.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ import io.getstream.chat.android.compose.sample.ui.component.CustomChatComponent
5656
import io.getstream.chat.android.compose.sample.ui.component.CustomMentionStyleFactory
5757
import io.getstream.chat.android.compose.sample.vm.SharedLocationViewModelFactory
5858
import io.getstream.chat.android.compose.state.mediagallerypreview.MediaGalleryPreviewResultType
59+
import io.getstream.chat.android.compose.state.messages.attachments.AttachmentPickerConfig
5960
import io.getstream.chat.android.compose.ui.components.composer.MessageInput
6061
import io.getstream.chat.android.compose.ui.components.messageoptions.MessageOptionItemVisibility
6162
import io.getstream.chat.android.compose.ui.components.messageoptions.defaultMessageOptionsState
@@ -148,6 +149,7 @@ class MessagesActivity : ComponentActivity() {
148149
colors = colors,
149150
shapes = shapes,
150151
typography = typography,
152+
attachmentPickerConfig = AttachmentPickerConfig(useSystemPicker = false),
151153
componentFactory = CustomChatComponentFactory(locationViewModelFactory = locationViewModelFactory),
152154
dateFormatter = ChatApp.dateFormatter,
153155
autoTranslationEnabled = ChatApp.autoTranslationEnabled,

stream-chat-android-compose/src/main/java/io/getstream/chat/android/compose/state/messages/attachments/AttachmentPickerConfig.kt

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,35 @@ import io.getstream.chat.android.compose.ui.theme.ChatTheme
3636
* }
3737
* ```
3838
*
39-
* @param useSystemPicker When `true`, uses the system's native file/media picker which does not require
40-
* storage permissions. When `false` (default), uses the in-app picker which shows a grid of media files
41-
* but requires storage permissions to be granted.
39+
* ## Permissions
40+
*
41+
* When using the in-app picker (`useSystemPicker = false`), the following permissions must be declared
42+
* in your app's `AndroidManifest.xml`:
43+
*
44+
* ```xml
45+
* <!-- For Android 12 (API 32) and below -->
46+
* <uses-permission
47+
* android:name="android.permission.READ_EXTERNAL_STORAGE"
48+
* android:maxSdkVersion="32" />
49+
*
50+
* <!-- For Android 13 (API 33) and above -->
51+
* <uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
52+
* <uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
53+
* <uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
54+
* ```
55+
*
56+
* When using the system picker (`useSystemPicker = true`), no storage permissions are required as the
57+
* system picker handles permissions internally.
58+
*
59+
* @param useSystemPicker When `true` (default), uses the system's native file/media picker which does not require
60+
* storage permissions. When `false`, uses the in-app picker which shows a grid of media files but requires
61+
* storage permissions to be granted and declared in your manifest.
4262
* @param modes The list of [AttachmentPickerMode] instances that define which attachment types are available.
4363
* The order of modes determines the order of tabs in the picker. Defaults to gallery, files, camera, poll,
4464
* and commands.
4565
*/
4666
public data class AttachmentPickerConfig(
47-
val useSystemPicker: Boolean = false,
67+
val useSystemPicker: Boolean = true,
4868
val modes: List<AttachmentPickerMode> = DefaultAttachmentPickerModes,
4969
)
5070

stream-chat-android-ui-common/src/main/AndroidManifest.xml

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,6 @@
1818
package="io.getstream.chat.android.ui.common"
1919
>
2020

21-
<uses-permission
22-
android:name="android.permission.READ_EXTERNAL_STORAGE"
23-
android:maxSdkVersion="32"
24-
/>
25-
<uses-permission
26-
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
27-
android:maxSdkVersion="29"
28-
/>
29-
30-
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
31-
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
32-
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
33-
3421
<queries>
3522
<intent>
3623
<action android:name="android.media.action.VIDEO_CAPTURE" />

stream-chat-android-ui-components-sample/src/main/AndroidManifest.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,21 @@
2020

2121
<uses-permission android:name="android.permission.INTERNET" />
2222

23+
<!-- Storage permissions for in-app attachment picker (useSystemPicker = false) -->
24+
<uses-permission
25+
android:name="android.permission.READ_EXTERNAL_STORAGE"
26+
android:maxSdkVersion="32"
27+
/>
28+
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
29+
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
30+
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
31+
32+
<!-- Storage permission for downloading attachments (Android 9 and below) -->
33+
<uses-permission
34+
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
35+
android:maxSdkVersion="29"
36+
/>
37+
2338
<application
2439
android:name="io.getstream.chat.ui.sample.application.App"
2540
android:allowBackup="false"

stream-chat-android-ui-components/src/main/kotlin/io/getstream/chat/android/ui/feature/messages/composer/MessageComposerViewStyle.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1438,7 +1438,7 @@ public data class MessageComposerViewStyle(
14381438

14391439
val useDefaultSystemMediaPicker = a.getBoolean(
14401440
R.styleable.MessageComposerView_streamUiMessageComposerAttachmentsPickerSystemPickerEnabled,
1441-
false,
1441+
true,
14421442
)
14431443
val systemMediaPickerVisualMediaAllowMultiple = a.getBoolean(
14441444
R.styleable.MessageComposerView_streamUiMessageComposerAttachmentsPickerSystemPickerVisualMediaAllowMultiple,

stream-chat-android-ui-components/src/main/kotlin/io/getstream/chat/android/ui/feature/messages/composer/attachment/picker/AttachmentsPickerDialogStyle.kt

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,29 @@ import io.getstream.chat.android.ui.helper.ViewStyle
2626
/**
2727
* Style for [AttachmentsPickerDialogFragment].
2828
*
29-
* @param useDefaultSystemMediaPicker If the system pickers should be used that does not require the `READ_MEDIA` permission.
29+
* ## Permissions
30+
*
31+
* When using the in-app picker (`useDefaultSystemMediaPicker = false`), the following permissions must be declared
32+
* in your app's `AndroidManifest.xml`:
33+
*
34+
* ```xml
35+
* <!-- For Android 12 (API 32) and below -->
36+
* <uses-permission
37+
* android:name="android.permission.READ_EXTERNAL_STORAGE"
38+
* android:maxSdkVersion="32" />
39+
*
40+
* <!-- For Android 13 (API 33) and above -->
41+
* <uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
42+
* <uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
43+
* <uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
44+
* ```
45+
*
46+
* When using the system picker (`useDefaultSystemMediaPicker = true`), no storage permissions are required as the
47+
* system picker handles permissions internally.
48+
*
49+
* @param useDefaultSystemMediaPicker If the system pickers should be used. When `true` (default), uses the system's
50+
* native file/media picker which does not require storage permissions. When `false`, uses the in-app picker which
51+
* shows a grid of media files but requires storage permissions to be granted and declared in your manifest.
3052
* @param saveAttachmentsOnDismiss If the selected attachments should be saved when the dialog is dismissed.
3153
* @param attachmentsPickerBackgroundColor The background color of the picker.
3254
* @param allowAccessButtonTextStyle The text style used for all the buttons used to request required permissions.
@@ -74,7 +96,7 @@ import io.getstream.chat.android.ui.helper.ViewStyle
7496
* @param systemMediaPickerVisualMediaType The type of visual media that can be picked via the system media picker.
7597
*/
7698
public data class AttachmentsPickerDialogStyle(
77-
val useDefaultSystemMediaPicker: Boolean = false,
99+
val useDefaultSystemMediaPicker: Boolean = true,
78100
val saveAttachmentsOnDismiss: Boolean,
79101
@ColorInt val attachmentsPickerBackgroundColor: Int,
80102
val allowAccessButtonTextStyle: TextStyle,

0 commit comments

Comments
 (0)