-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feat] 밈 등록하기 기능 #256
[Feat] 밈 등록하기 기능 #256
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
진짜 고생했어!!
val contentResolver: ContentResolver = context.contentResolver | ||
val fileName = getFileName(contentResolver, uri) ?: return null // 파일 이름 얻기 | ||
val tempFile = File(context.cacheDir, fileName) | ||
|
||
try { | ||
val inputStream: InputStream? = contentResolver.openInputStream(uri) | ||
val outputStream: OutputStream = FileOutputStream(tempFile) | ||
|
||
inputStream?.use { input -> | ||
outputStream.use { output -> | ||
input.copyTo(output) | ||
} | ||
} | ||
return tempFile | ||
} catch (e: Exception) { | ||
e.printStackTrace() | ||
} | ||
return null | ||
} | ||
|
||
private fun getFileName(contentResolver: ContentResolver, uri: Uri): String? { | ||
val cursor = contentResolver.query(uri, null, null, null, null) | ||
return cursor?.use { | ||
if (it.moveToFirst()) { | ||
val index = it.getColumnIndex("_display_name") | ||
it.getString(index) | ||
} else null | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이렇게 했을 때 실제 fileName이랑 photopicker uri에서 fileName 얻어왔을 때랑 동일해??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
정상 업로드 된것을 봐서는 동일해
val imagePicker = | ||
rememberLauncherForActivityResult(contract = ActivityResultContracts.PickVisualMedia()) { uri -> | ||
if (uri != null) { | ||
onIntent(RegisterIntent.SetImageFromGallery(uri.toString())) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
각 API Level에 해당하는 권한체크는 없어도 되려나?
<!-- Devices running Android 12L (API level 32) or lower -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" android:maxSdkVersion="32" />
<!-- Devices running Android 13 (API level 33) or higher -->
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
<!-- To handle the reselection within the app on Android 14 (API level 34) -->
<uses-permission android:name="android.permission.READ_MEDIA_VISUAL_USER_SELECTED" />
`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://mundroid.tistory.com/2, https://developer.android.com/training/data-storage/shared/photopicker
따로 권한을 명시하지 않아도 되고, 31버전이하의 경우 문서 선택기로 열린다고 하더라구
커스텀 갤러리가 아니라면 휘뚜루마뚜루 써도 될듯?
작업 내역 (Required)