티스토리 뷰
Hi i am android developer who works in Korea and i was born in Korea and raised.
I am studying english and this is part of it. I know there are a lot of mistakes but if you let me know those i'll really appreciate it.
photo picker(android developer link)
Before Android 13, you need to request
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
to access photos or videos.
But from Android 13, you can access these media files with [photo picker] without requesting permission.
If you use it, user can choose the files app can access. if you have a experience of iPhone you are familiar with
1. You can use [photo picker] if the device meets the following criteria
- Android 11(Api 30) or high
- Receive changes to Modular System Components through Google System Updates
The first important thing is that from Android 11, you can use [photo picker] and
you need to use androidx.activity:activity more than high or equal 1.6.1
You can choose either below
- PickVisualMedia -> select only on media file
- PickMultipleVisualMedia -> select multiple meida files
There are examples
// need only one media file
val pickMedia = registerForActivityResult(PickVisualMedia()) { uri ->
if (uri != null) {
// success
} else {
// no choise
}
}
// image and video
pickMedia.launch(PickVisualMediaRequest(PickVisualMedia.ImageAndVideo))
// only image
pickMedia.launch(PickVisualMediaRequest(PickVisualMedia.ImageOnly))
// only video
pickMedia.launch(PickVisualMediaRequest(PickVisualMedia.VideoOnly))
// you can set the avilable type
val mimeType = "image/gif"
pickMedia.launch(PickVisualMediaRequest(PickVisualMedia.SingleMimeType(mimeType)))
// If you need to multiple media files
val pickMultipleMedia =
registerForActivityResult(PickMultipleVisualMedia(5)) { uris ->
.
if (uris.isNotEmpty()) {
// Result is list type
} else {
//
}
}
And you can see the result below.
Left is less than Android 13, right is Android 13
![]() |
![]() |
If you need to check app can use photo picker, you can use this code.
This code need CompileSdkVersion is 33 or high.
import android.os.ext.SdkExtensions.getExtensionVersion
private fun isPhotoPickerAvailable(): Boolean {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
true
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
getExtensionVersion(Build.VERSION_CODES.R) >= 2
} else {
false
}
}
fun handlePhotoPickerLaunch() {
if (isPhotoPickerAvailable()) {
} else {
}
}
- Total
- Today
- Yesterday
- android14
- intent-filter
- android14 변경점
- 안드로이드 컴포즈
- android-compose
- android compose
- androidcompose
- 안드로이드14
- android13
- 안드로이드 터치 이벤트
- 박달과학화훈련장
- 안드로이드 14 변경점
- photopicker
- android touch event
- android
- compose drag
- 안드로이드 13
- 씽크101
- 안드로이드 14
- 박달과학화
- 안드로이드 컴포즈 드래그
- 안드로이드
- 컴포즈
- photo-picker
- photo picker
- subcomposelayout
- android 13
- 안드로이드13
- targetsdk 33
- android partial access
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |