val projection = arrayOf(MediaStore.Images.Media._ID, MediaStore.Images.Media.DISPLAY_NAME, MediaStore.Images.Media.DATE_TAKEN)
contentResolver.query(uri, projection, null, null)?.let {
with(it) {
if(moveToFirst()) {
val id = getLong(getColumnIndex(MediaStore.Images.Media._ID))
val contentUri = Uri.withAppendedPath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, id.toString())
Glide.with(this@Activity).load(contentUri).into(iv_profile)
}
close()
}
} ?:run {
showToast(this, "사진이 없습니다.")
Glide.with(this).load(R.drawable.no_profile).into(iv_profile)
}
'Before 2022 > Android' 카테고리의 다른 글
Kotlin으로 Custom View 만들기 (0) | 2020.08.25 |
---|---|
kotlin + libphonenumber를 활용한 전화번호 포맷 통일 (0) | 2020.07.16 |
Kotlin + Retrofit2 + Okhttp3을 활용한 REST API 기본 메소드 작성 (0) | 2020.07.16 |
AndroidX의 Android Security를 활용한 SharedPreferences 암호화 (0) | 2020.07.16 |
AlertDialog 스타일을 호출한 내부 파일에서 변경하기 (0) | 2019.07.11 |